https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86243

            Bug ID: 86243
           Summary: unknown attributes causing hard error
           Product: gcc
           Version: 7.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: h2+bugs at fsfe dot org
  Target Milestone: ---

The following code (based on
http://open-std.org/JTC1/SC22/WG21/docs/papers/2017/p0479r1.html)

int main()
{
    if (1 == 2) [[unlikely]]
        throw int{};

    return 2;
}

produces an error:

% g++7 -std=c++17 test.cpp
test.cpp: In function 'int main()':
test.cpp:3:18: error: expected identifier before '[' token
     if (1 == 2) [[unlikely]]
                  ^
test.cpp: In lambda function:
test.cpp:4:9: error: expected '{' before 'throw'
         throw int{};
         ^~~~~
test.cpp: In function 'int main()':
test.cpp:4:9: error: expected ';' before 'throw'

This strongly looks like a bug. If one encloses the if-block in braces, I
instead get a warning:

int main()
{
    if (1 == 2) [[unlikely]]
    {
        throw int{};
    }

    return 2;
}

results in:

% g++7 -std=c++17 test.cpp
test.cpp: In function 'int main()':
test.cpp:3:17: warning: attributes at the beginning of statement are ignored
[-Wattributes]
     if (1 == 2) [[unlikely]]
                 ^
Note that I am not even setting -Wall or -Wextra. Even then I would think that
unknown attributes should just be silently ignored as suggested by the
standard, or not?

Thanks for your help!

Tested versions:
g++7 (FreeBSD Ports Collection) 7.3.1 20180531
g++8 (FreeBSD Ports Collection) 8.1.1 20180608
g++9 (FreeBSD Ports Collection) 9.0.0 20180603 (experimental)

Reply via email to