public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105516] New: auto(<identifier>) is incorrectly parsed as declaration
@ 2022-05-07 14:15 cooky.ykooc922 at gmail dot com
2022-05-07 14:26 ` [Bug c++/105516] " mpolacek at gcc dot gnu.org
2022-05-07 14:44 ` hewillk at gmail dot com
0 siblings, 2 replies; 3+ messages in thread
From: cooky.ykooc922 at gmail dot com @ 2022-05-07 14:15 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/105516] auto(<identifier>) is incorrectly parsed as declaration
2022-05-07 14:15 [Bug c++/105516] New: auto(<identifier>) is incorrectly parsed as declaration cooky.ykooc922 at gmail dot com
@ 2022-05-07 14:26 ` mpolacek at gcc dot gnu.org
2022-05-07 14:44 ` hewillk at gmail dot com
1 sibling, 0 replies; 3+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-05-07 14:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105516
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
CC| |mpolacek at gcc dot gnu.org
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Not a bug, "auto(x);" is interpreted as "auto x;". Use +auto(x); if you want
that to be an expression.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/105516] auto(<identifier>) is incorrectly parsed as declaration
2022-05-07 14:15 [Bug c++/105516] New: auto(<identifier>) is incorrectly parsed as declaration cooky.ykooc922 at gmail dot com
2022-05-07 14:26 ` [Bug c++/105516] " mpolacek at gcc dot gnu.org
@ 2022-05-07 14:44 ` hewillk at gmail dot com
1 sibling, 0 replies; 3+ messages in thread
From: hewillk at gmail dot com @ 2022-05-07 14:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105516
康桓瑋 <hewillk at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |hewillk at gmail dot com
--- Comment #2 from 康桓瑋 <hewillk at gmail dot com> ---
Dup of PR103653?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-05-07 14:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-07 14:15 [Bug c++/105516] New: auto(<identifier>) is incorrectly parsed as declaration cooky.ykooc922 at gmail dot com
2022-05-07 14:26 ` [Bug c++/105516] " mpolacek at gcc dot gnu.org
2022-05-07 14:44 ` hewillk at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).