Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[[maybe_unused]] and Constructors

Tags:

c++

c++17

Trying to compile the sqlpp17 codebase with gcc 8.2.1 and clang 6.0.1 have been a really strange experience. The code pushes the compilers to the limits and I hit probably a few compiler bugs in the meantime.

From the GCC Docs, [[maybe_unused]] is implemented since version 7, but if used this way:

struct foo {
    foo([[maybe_unused]] bool thing1)
    {
    }
};

I hit this specific error:

<source>:2:9: error: expected unqualified-id before '[' token
     foo([[maybe_unused]] bool thing1)
         ^
<source>:2:9: error: expected ')' before '[' token
     foo([[maybe_unused]] bool thing1)
        ~^
         )
Compiler returned: 1

Now, I know too little about C++17 to know if this error is correct, I know that clang 6 compiles that part fine (and fails somewhere else).

So, who's right, clang or gcc? (flags are -std=gnu++17 for both clang and gcc, generated by CMake)

like image 660
Tomaz Canabrava Avatar asked Sep 10 '18 17:09

Tomaz Canabrava


1 Answers

This is a known bug in g++: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81429 G++ doesn't parse correctly [[maybe_unused]] attribute for first argument of the constructor.

like image 100
SergeyA Avatar answered Nov 09 '22 07:11

SergeyA