MINGW-packages
MINGW-packages copied to clipboard
Calling a function declared as weak causes a segfault
Description / Steps to reproduce the issue
Consider following code:
1.cpp
__attribute__((__weak__)) void foo();
int main() {foo();}
2.cpp
__attribute__((__weak__)) void foo() {}
Run g++ 1.cpp 2.cpp && ./a.exe
.
Expected behavior
No runtime or compile-time errors. (Also no errors if I remove the attribute from the declaration and/or definition, but this.)
Actual behavior
This segfaults.
If only the definition has the attribute, then I get an undefined reference.
If only the declaration has the attribute, then the code works (but this is unconvenient, since it means you either can't declare the function in a header, or have to use macros to conditionally remove the attribute from it).
Verification
- [X] I have verified that my MSYS2 is up-to-date before submitting the report (see https://www.msys2.org/docs/updating/)
Windows Version
MINGW64_NT-10.0-19045
MINGW environments affected
(didn't test others)
- [X] MINGW64
- [ ] MINGW32
- [X] UCRT64
- [ ] CLANG64
- [ ] CLANG32
- [ ] CLANGARM64
Are you willing to submit a PR?
No response