[Bug c++/105516] New: auto(<identifier>) is incorrectly parsed as declaration
cooky.ykooc922 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sat May 7 14:15:16 GMT 2022
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
More information about the Gcc-bugs
mailing list