jrl-umi3218 / jrl-cmakemodules

CMake utility toolbox
https://jrl-cmakemodules.readthedocs.io/en/master/
Other
61 stars 47 forks source link

Use c++11 attribute when C++11 is activated #725

Closed jorisv closed 2 weeks ago

jorisv commented 3 weeks ago

With gcc < 13, mixing old __attribute__ keyword and C++11 [[ ]] attribute can create some error.

To reproduce, we can compile the following code snippet on godbot:

class [[gnu::visibility ("default")]] [[deprecated]] SomeClass1
{};

class [[gnu::visibility ("default"), deprecated]] SomeClass2
{};

class __attribute__((visibility ("default")))  __attribute__((deprecated)) SomeClass3
{};

class __attribute__((visibility ("default"))) [[deprecated]] SomeClass4
{};

int main()
{
    SomeClass1 c1;
    SomeClass2 c2;
    SomeClass3 c3;
    SomeClass4 c4;
}

SomeClass4 will not compile on gcc < 13 with the following error:

<source>:10:47: error: expected identifier before '[' token
   10 | class __attribute__((visibility ("default"))) [[deprecated]] SomeClass4

This code build well with clang >= 3.0 when -std=c++11 is activated. If we remove SomeClass4 and deprecated attribute. This code build with gcc >= 4.8 when -std=c++11 is activated. deprecated attribute is working fine in gcc >= 5.

bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96117

jorisv commented 3 weeks ago

Tested in https://github.com/stack-of-tasks/pinocchio/pull/2469