exercism / cpp

Exercism exercises in C++.
https://exercism.org/tracks/cpp
MIT License
259 stars 214 forks source link

last-will: `weak` attributes cause problems with Clang #670

Closed siebenschlaefer closed 1 year ago

siebenschlaefer commented 1 year ago

When compiling a (correct) solution of the last-will exercise with Clang (version 15.0.7 on Linux) I get the following error:

/vagrant/exercism/cpp/last-will/last_will_test.cpp:30:53: error: attribute declaration must precede definition [-Werror,-Wignored-attributes]
    int assemble_account_number(int) __attribute__((weak));
                                                    ^
/vagrant/exercism/cpp/last-will/last_will.cpp:45:9: note: previous definition is here
    int assemble_account_number(int secret_modifier) {
        ^
/vagrant/exercism/cpp/last-will/last_will_test.cpp:31:40: error: attribute declaration must precede definition [-Werror,-Wignored-attributes]
    int assemble_code() __attribute__((weak));
                                       ^
/vagrant/exercism/cpp/last-will/last_will.cpp:50:9: note: previous definition is here
    int assemble_code() {
        ^

For some reason Clang doesn't like this __attribute__((weak)).
I couldn't find a quick solution so I'm opening this issue.

siebenschlaefer commented 1 year ago

What seem to work is moving these weak declarations (lines 28-35) to the beginning of the file, before #include "last_will.cpp" I've tested that with GCC-9.5.0, GCC-12.1.0, Clang-11.1.0, and Clang-15.0.7 on Linux.

vaeng commented 1 year ago

Thanks for finding this! Now we only need the same thing to prep a class to make the test run when it is not implemented. Do you have an idea?