public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cooky.ykooc922 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/105516] New: auto(<identifier>) is incorrectly parsed as declaration
Date: Sat, 07 May 2022 14:15:16 +0000	[thread overview]
Message-ID: <bug-105516-4@http.gcc.gnu.org/bugzilla/> (raw)

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	other threads:[~2022-05-07 14:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-07 14:15 cooky.ykooc922 at gmail dot com [this message]
2022-05-07 14:26 ` [Bug c++/105516] " mpolacek at gcc dot gnu.org
2022-05-07 14:44 ` hewillk at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-105516-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).