[Bug c++/86564] New: Declaration containing qualified-id interpreted as function-style cast

zhonghao at pku dot org.cn gcc-bugzilla@gcc.gnu.org
Wed Jul 18 05:54:00 GMT 2018


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

            Bug ID: 86564
           Summary: Declaration containing qualified-id interpreted as
                    function-style cast
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhonghao at pku dot org.cn
  Target Milestone: ---

The code is as follow:

 struct foo {
 static bool const value = false;
 };

 int main() {
 int v(int(foo::value));
 }

g++ accepts it, but clang++ rejects it:

code0.cpp:6:17: error: parameter declarator cannot be qualified
 int v(int(foo::value));
           ~~~~~^
code0.cpp:6:7: warning: parentheses were disambiguated as a function
      declaration [-Wvexing-parse]
 int v(int(foo::value));
      ^~~~~~~~~~~~~~~~~
code0.cpp:6:8: note: add a pair of parentheses to declare a variable
 int v(int(foo::value));
       ^
       (              )
1 warning and 1 error generated.

The paragraphs in the C++ Standard, 6.8 and 8.2 say that disambiguation is
purely syntactic, and any construct that could be a declaration is taken and
parsed as a declaration. The grammar of C++ allows a declarator-id be a
qualified-id, which makes for the following be a well-formed construct

    struct foo {
      static int value;
    };

    int (foo::value);

Thus, the function declaration in main above would contain a parameter whose
name is a qualified-id. This is ill-formed and should be rejected.


More information about the Gcc-bugs mailing list