Skip to content

[mingw-w64-x86_64-gcc] weak handle_contract_violation from libstdc++exp.a is not extracted during linking #30543

Description

@Alias10294

Description / Steps to reproduce the issue

The default C++26 contract violation handler provided by
libstdc++exp.a is not resolved when linking a program with
-fcontracts on MINGW64.

The archive contains the expected symbol, but it is defined as a weak
symbol and does not appear to be extracted automatically by the linker.

Steps to reproduce

  1. Create a code file that uses the C++26 contracts such as this code
# bug_repro.cpp
void f(int value)
  pre(value > 0)
{ }

int main()
{ f(1); }
  1. attempt to compile it using c++ -std=c++26 -fcontracts bug_repro.cpp -o bug_repro.exe

Environment

  • C++ version : c++.exe (Rev5, Built by MSYS2 project) 16.1.0
  • ld version : GNU ld (GNU Binutils) 2.46.1
  • mingw-w64-x86_64-gcc version : mingw-w64-x86_64-gcc 16.1.0-5
  • mingw-w64-x86_64-gcc-libs version : mingw-w64-x86_64-gcc-libs 16.1.0-5
  • mingw-w64-x86_64-binutils version : mingw-w64-x86_64-binutils 2.46.1-2

Expected behavior

The program should compile without any kind of error.

Actual behavior

The compiler output this error twice (for the proposed bug_repro.cpp):

undefined reference to `handle_contract_violation(std::contracts::contract_violation const&)'

Verification

Windows Version

MINGW64_NT-10.0-26200

MINGW environments affected

  • MINGW64
  • MINGW32
  • UCRT64
  • CLANG64
  • CLANGARM64

Are you willing to submit a PR?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions