public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/112410] New: error when auto(x) is used in a variable initializer
@ 2023-11-06 16:27 vanyacpp at gmail dot com
  2023-11-06 16:34 ` [Bug c++/112410] " mpolacek at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: vanyacpp at gmail dot com @ 2023-11-06 16:27 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112410
           Summary: error when auto(x) is used in a variable initializer
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vanyacpp at gmail dot com
  Target Milestone: ---

int x = auto(42); // OK
int y(auto(42));  // error

On the second line GCC -std=c++23 gives an error:

error: non-function 'y' declared as implicit template

I believe the code is correct and should compile without errors.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/112410] error when auto(x) is used in a variable initializer
  2023-11-06 16:27 [Bug c++/112410] New: error when auto(x) is used in a variable initializer vanyacpp at gmail dot com
@ 2023-11-06 16:34 ` mpolacek at gcc dot gnu.org
  2023-11-06 16:37 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-11-06 16:34 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
                 CC|                            |mpolacek at gcc dot gnu.org
   Last reconfirmed|                            |2023-11-06
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I think you're right.  Same for

int z(auto{42});

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/112410] error when auto(x) is used in a variable initializer
  2023-11-06 16:27 [Bug c++/112410] New: error when auto(x) is used in a variable initializer vanyacpp at gmail dot com
  2023-11-06 16:34 ` [Bug c++/112410] " mpolacek at gcc dot gnu.org
@ 2023-11-06 16:37 ` pinskia at gcc dot gnu.org
  2023-11-06 17:16 ` mpolacek at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-06 16:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

Looks like GCC is messing the Most vexing parse here.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/112410] error when auto(x) is used in a variable initializer
  2023-11-06 16:27 [Bug c++/112410] New: error when auto(x) is used in a variable initializer vanyacpp at gmail dot com
  2023-11-06 16:34 ` [Bug c++/112410] " mpolacek at gcc dot gnu.org
  2023-11-06 16:37 ` pinskia at gcc dot gnu.org
@ 2023-11-06 17:16 ` mpolacek at gcc dot gnu.org
  2023-11-16  3:24 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-11-06 17:16 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Part of the problem seems to be that fully_implicit_function_template_p is set.
 I'd like to poke more.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/112410] error when auto(x) is used in a variable initializer
  2023-11-06 16:27 [Bug c++/112410] New: error when auto(x) is used in a variable initializer vanyacpp at gmail dot com
                   ` (2 preceding siblings ...)
  2023-11-06 17:16 ` mpolacek at gcc dot gnu.org
@ 2023-11-16  3:24 ` cvs-commit at gcc dot gnu.org
  2023-11-16  3:25 ` mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-16  3:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:70060dadfbf0d0af5f4cab5f3aff3223a4523606

commit r14-5514-g70060dadfbf0d0af5f4cab5f3aff3223a4523606
Author: Marek Polacek <polacek@redhat.com>
Date:   Thu Nov 9 12:25:25 2023 -0500

    c++: fix parsing with auto(x) [PR112410]

    Here we are wrongly parsing

      int y(auto(42));

    which uses the C++23 cast-to-prvalue feature, and initializes y to 42.
    However, we were treating the auto as an implicit template parameter.

    Fixing the auto{42} case is easy, but when auto is followed by a (,
    I found the fix to be much more involved.  For instance, we cannot
    use cp_parser_expression, because that can give hard errors.  It's
    also necessary to disambiguate 'auto(i)' as 'auto i', not a cast.
    auto(), auto(int), auto(f)(int), auto(*), auto(i[]), auto(...), etc.
    are all function declarations.

    This patch rectifies that by undoing the implicit function template
    modification.  In the test above, we should notice that the parameter
    list is ill-formed, and since we've synthesized an implicit template
    parameter, we undo it by calling abort_fully_implicit_template.  Then,
    we'll parse the "(auto(42))" as an initializer.

            PR c++/112410

    gcc/cp/ChangeLog:

            * parser.cc (cp_parser_direct_declarator): Maybe call
            abort_fully_implicit_template if it turned out the parameter list
was
            ill-formed.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp23/auto-fncast13.C: New test.
            * g++.dg/cpp23/auto-fncast14.C: New test.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/112410] error when auto(x) is used in a variable initializer
  2023-11-06 16:27 [Bug c++/112410] New: error when auto(x) is used in a variable initializer vanyacpp at gmail dot com
                   ` (3 preceding siblings ...)
  2023-11-16  3:24 ` cvs-commit at gcc dot gnu.org
@ 2023-11-16  3:25 ` mpolacek at gcc dot gnu.org
  2023-12-12  0:37 ` cvs-commit at gcc dot gnu.org
  2023-12-12  0:38 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-11-16  3:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk so far; I want to fix it in 13 too.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/112410] error when auto(x) is used in a variable initializer
  2023-11-06 16:27 [Bug c++/112410] New: error when auto(x) is used in a variable initializer vanyacpp at gmail dot com
                   ` (4 preceding siblings ...)
  2023-11-16  3:25 ` mpolacek at gcc dot gnu.org
@ 2023-12-12  0:37 ` cvs-commit at gcc dot gnu.org
  2023-12-12  0:38 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-12  0:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:60979215517629400902938b1c5666f97d0653cf

commit r13-8147-g60979215517629400902938b1c5666f97d0653cf
Author: Marek Polacek <polacek@redhat.com>
Date:   Thu Nov 9 12:25:25 2023 -0500

    c++: fix parsing with auto(x) [PR112410]

    Here we are wrongly parsing

      int y(auto(42));

    which uses the C++23 cast-to-prvalue feature, and initializes y to 42.
    However, we were treating the auto as an implicit template parameter.

    Fixing the auto{42} case is easy, but when auto is followed by a (,
    I found the fix to be much more involved.  For instance, we cannot
    use cp_parser_expression, because that can give hard errors.  It's
    also necessary to disambiguate 'auto(i)' as 'auto i', not a cast.
    auto(), auto(int), auto(f)(int), auto(*), auto(i[]), auto(...), etc.
    are all function declarations.

    This patch rectifies that by undoing the implicit function template
    modification.  In the test above, we should notice that the parameter
    list is ill-formed, and since we've synthesized an implicit template
    parameter, we undo it by calling abort_fully_implicit_template.  Then,
    we'll parse the "(auto(42))" as an initializer.

            PR c++/112410

    gcc/cp/ChangeLog:

            * parser.cc (cp_parser_direct_declarator): Maybe call
            abort_fully_implicit_template if it turned out the parameter list
was
            ill-formed.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp23/auto-fncast13.C: New test.
            * g++.dg/cpp23/auto-fncast14.C: New test.

    (cherry picked from commit 70060dadfbf0d0af5f4cab5f3aff3223a4523606)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/112410] error when auto(x) is used in a variable initializer
  2023-11-06 16:27 [Bug c++/112410] New: error when auto(x) is used in a variable initializer vanyacpp at gmail dot com
                   ` (5 preceding siblings ...)
  2023-12-12  0:37 ` cvs-commit at gcc dot gnu.org
@ 2023-12-12  0:38 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-12-12  0:38 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-12-12  0:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-06 16:27 [Bug c++/112410] New: error when auto(x) is used in a variable initializer vanyacpp at gmail dot com
2023-11-06 16:34 ` [Bug c++/112410] " mpolacek at gcc dot gnu.org
2023-11-06 16:37 ` pinskia at gcc dot gnu.org
2023-11-06 17:16 ` mpolacek at gcc dot gnu.org
2023-11-16  3:24 ` cvs-commit at gcc dot gnu.org
2023-11-16  3:25 ` mpolacek at gcc dot gnu.org
2023-12-12  0:37 ` cvs-commit at gcc dot gnu.org
2023-12-12  0:38 ` mpolacek at gcc dot gnu.org

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).