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

            Bug ID: 105516
           Summary: auto(<identifier>) is incorrectly parsed as
                    declaration
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cooky.ykooc922 at gmail dot com
  Target Milestone: ---

>From the code snippet below:

int main() {
  int x = 1;
  auto(1); // ok
  static_cast<void>(auto(x)); // ok
  auto{x}; // ok
  auto(x); // error
}

The compiler emits an error with a message:
<source>: In function 'int main()':
<source>:6:3: error: declaration of 'auto x' has no initializer
    6 |   auto(x); // error
      |   ^~~~
Compiler returned: 1

This should be valid because the expression statement line 6 contains a valid
explicit type conversion `auto(expression)`, where a parser may misinterpret it
as a declaration with an `auto` specifier that contains an identifier and no
initializer but is obviously enclosed with parenthesis or maybe because it
would parse as function reference or pointer declaration that has `auto`
declared return type just like:

auto (*fn)() = +[]{ return 0; };

But i'm unsure, it's just a guest anyway :> 

Flag: -std=c++23

Compiler Explorer Link: https://godbolt.org/z/xoKa9Kzch

Reply via email to