public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/98441] New: member function pointer incorrectly parsed as having trailing return type
@ 2020-12-25  0:24 daniel.santos at pobox dot com
  2020-12-25  0:29 ` [Bug c++/98441] " daniel.santos at pobox dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: daniel.santos at pobox dot com @ 2020-12-25  0:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98441
           Summary: member function pointer incorrectly parsed as having
                    trailing return type
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: daniel.santos at pobox dot com
  Target Milestone: ---

When declaring pointer to a member function pointer using atuo& as the
function's return type, we get a bad parse:

struct a {
    int& mfn();
};

void fn()
{
    int&  (a::*myvar1)(void) = &a::mfn;
    auto& (a::*myvar2)(void) = &a::mfn;
    auto  (a::*myvar3)(void) = &a::mfn;
}

Results in:

<source>: In function 'void fn()':
<source>:8:5: error: 'myvar2' function with trailing return type has 'auto&' as
its type rather than plain 'auto'
    8 |     auto& (a::*myvar2)(void) = &a::mfn;
      |     ^~~~

However, it builds on GCC 9 and is alleged to build on MSVC.  The above example
is simplified from the original sources:

https://github.com/freeorion/freeorion/blob/v0.4.10.1/python/UniverseWrapper.cpp#L193

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

* [Bug c++/98441] member function pointer incorrectly parsed as having trailing return type
  2020-12-25  0:24 [Bug c++/98441] New: member function pointer incorrectly parsed as having trailing return type daniel.santos at pobox dot com
@ 2020-12-25  0:29 ` daniel.santos at pobox dot com
  2020-12-27 20:23 ` [Bug c++/98441] [10/11 Regression] " redi at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: daniel.santos at pobox dot com @ 2020-12-25  0:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Daniel Santos <daniel.santos at pobox dot com> ---
Also, I build gcc with:

-O42 -ffast-math -ffuzzy-dice -felide-function-bodies -pipe-clogged

but that shouldn't make a difference.

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

* [Bug c++/98441] [10/11 Regression] member function pointer incorrectly parsed as having trailing return type
  2020-12-25  0:24 [Bug c++/98441] New: member function pointer incorrectly parsed as having trailing return type daniel.santos at pobox dot com
  2020-12-25  0:29 ` [Bug c++/98441] " daniel.santos at pobox dot com
@ 2020-12-27 20:23 ` redi at gcc dot gnu.org
  2020-12-27 20:26 ` [Bug c++/98441] [11 " redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2020-12-27 20:23 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |10.3
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |rejects-valid
     Ever confirmed|0                           |1
                 CC|                            |mpolacek at gcc dot gnu.org
            Summary|member function pointer     |[10/11 Regression] member
                   |incorrectly parsed as       |function pointer
                   |having trailing return type |incorrectly parsed as
                   |                            |having trailing return type
   Last reconfirmed|                            |2020-12-27

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Started to be rejected with r11-2085:

    c++: Improve checking of decls with trailing return type [PR95820]

    This is an ICE-on-invalid but I've been seeing it when reducing
    various testcases, so it's more important for me than usually.

    splice_late_return_type now checks that if we've seen a late return
    type, the function return type was auto.  That's a fair assumption
    but grokdeclarator/cdk_function wasn't giving errors for function
    pointers and similar.  So we want to perform various checks not only
    when funcdecl_p || inner_declarator == NULL.  But only give the
    !late_return_type errors when funcdecl_p, to accept e.g.

    auto (*fp)() = f;

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

* [Bug c++/98441] [11 Regression] member function pointer incorrectly parsed as having trailing return type
  2020-12-25  0:24 [Bug c++/98441] New: member function pointer incorrectly parsed as having trailing return type daniel.santos at pobox dot com
  2020-12-25  0:29 ` [Bug c++/98441] " daniel.santos at pobox dot com
  2020-12-27 20:23 ` [Bug c++/98441] [10/11 Regression] " redi at gcc dot gnu.org
@ 2020-12-27 20:26 ` redi at gcc dot gnu.org
  2020-12-29  9:07 ` daniel.santos at pobox dot com
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2020-12-27 20:26 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[10/11 Regression] member   |[11 Regression] member
                   |function pointer            |function pointer
                   |incorrectly parsed as       |incorrectly parsed as
                   |having trailing return type |having trailing return type
   Target Milestone|10.3                        |11.0
      Known to fail|10.2.0                      |

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Daniel Santos from comment #0)
> However, it builds on GCC 9 and is alleged to build on MSVC.  The above
> example is simplified from the original sources:

Are you sure this fails with 10.2.0? I only see it fail with 11.0 and not gcc
version 10.2.1 20201125 (but I didn't try a newer build from the gcc-10
branch).

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

* [Bug c++/98441] [11 Regression] member function pointer incorrectly parsed as having trailing return type
  2020-12-25  0:24 [Bug c++/98441] New: member function pointer incorrectly parsed as having trailing return type daniel.santos at pobox dot com
                   ` (2 preceding siblings ...)
  2020-12-27 20:26 ` [Bug c++/98441] [11 " redi at gcc dot gnu.org
@ 2020-12-29  9:07 ` daniel.santos at pobox dot com
  2020-12-29 10:17 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: daniel.santos at pobox dot com @ 2020-12-29  9:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Daniel Santos <daniel.santos at pobox dot com> ---
Created attachment 49850
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49850&action=edit
Gentoo gcc 10.2.0-r2 patches

(In reply to Jonathan Wakely from comment #3)
> (In reply to Daniel Santos from comment #0)
> > However, it builds on GCC 9 and is alleged to build on MSVC.  The above
> > example is simplified from the original sources:
> 
> Are you sure this fails with 10.2.0? I only see it fail with 11.0 and not
> gcc version 10.2.1 20201125 (but I didn't try a newer build from the gcc-10
> branch).

Well, yes, but this is Gentoo gcc-10.2.0-r2, so includes a patchset (attached).
 In that, 34_all_fundecl-ICE-PR95820.patch contains the following:

It's an unofficial backport of PR95820 where gcc ICEs on
invalid syntax. As creduce frequently end up in these ICEs
as in #730406 let's backport it to gcc-10.

https://gcc.gnu.org/PR95820
https://bugs.gentoo.org/730406
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -12029,14 +12029,11 @@ grokdeclarator (const cp_declarator *declarator,

            /* Handle a late-specified return type.  */
            tree late_return_type = declarator->u.function.late_return_type;
-           if (funcdecl_p
-               /* This is the case e.g. for
-                  using T = auto () -> int.  */
-               || inner_declarator == NULL)
+           if (true)
              {
                if (tree auto_node = type_uses_auto (type))
                  {
-                   if (!late_return_type)
+                   if (!late_return_type && funcdecl_p)
                      {
                        if (current_class_type
                            && LAMBDA_TYPE_P (current_class_type))

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

* [Bug c++/98441] [11 Regression] member function pointer incorrectly parsed as having trailing return type
  2020-12-25  0:24 [Bug c++/98441] New: member function pointer incorrectly parsed as having trailing return type daniel.santos at pobox dot com
                   ` (3 preceding siblings ...)
  2020-12-29  9:07 ` daniel.santos at pobox dot com
@ 2020-12-29 10:17 ` redi at gcc dot gnu.org
  2020-12-29 18:19 ` daniel.santos at pobox dot com
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2020-12-29 10:17 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|10.2.0                      |11.0
      Known to work|10.1.0                      |10.2.0

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
That's why you're asked to provide the output of 'gcc -v' by the instructions
at https://gcc.gnu.org/bugs/ (because we can't guess that your 10.2.0 is
different from ours).

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

* [Bug c++/98441] [11 Regression] member function pointer incorrectly parsed as having trailing return type
  2020-12-25  0:24 [Bug c++/98441] New: member function pointer incorrectly parsed as having trailing return type daniel.santos at pobox dot com
                   ` (4 preceding siblings ...)
  2020-12-29 10:17 ` redi at gcc dot gnu.org
@ 2020-12-29 18:19 ` daniel.santos at pobox dot com
  2020-12-31 19:17 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: daniel.santos at pobox dot com @ 2020-12-29 18:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Daniel Santos <daniel.santos at pobox dot com> ---
(In reply to Jonathan Wakely from comment #5)
> That's why you're asked to provide the output of 'gcc -v' by the
> instructions at https://gcc.gnu.org/bugs/ (because we can't guess that your
> 10.2.0 is different from ours).

You're correct; my apologies.  Sorry for the extra work!

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

* [Bug c++/98441] [11 Regression] member function pointer incorrectly parsed as having trailing return type
  2020-12-25  0:24 [Bug c++/98441] New: member function pointer incorrectly parsed as having trailing return type daniel.santos at pobox dot com
                   ` (5 preceding siblings ...)
  2020-12-29 18:19 ` daniel.santos at pobox dot com
@ 2020-12-31 19:17 ` mpolacek at gcc dot gnu.org
  2021-01-05 23:11 ` mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-12-31 19:17 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

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

* [Bug c++/98441] [11 Regression] member function pointer incorrectly parsed as having trailing return type
  2020-12-25  0:24 [Bug c++/98441] New: member function pointer incorrectly parsed as having trailing return type daniel.santos at pobox dot com
                   ` (6 preceding siblings ...)
  2020-12-31 19:17 ` mpolacek at gcc dot gnu.org
@ 2021-01-05 23:11 ` mpolacek at gcc dot gnu.org
  2021-01-07 21:20 ` cvs-commit at gcc dot gnu.org
  2021-01-07 21:23 ` mpolacek at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-01-05 23:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Looks like a simple thinko:

--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -12241,9 +12241,11 @@ grokdeclarator (const cp_declarator *declarator,
        tree late_return_type = declarator->u.function.late_return_type;
        if (tree auto_node = type_uses_auto (type))
          {
-       if (!late_return_type && funcdecl_p)
+       if (!late_return_type)
          {
-           if (current_class_type
+           if (!funcdecl_p)
+             /* auto (*fp)() = f; is OK.  */;
+           else if (current_class_type
            && LAMBDA_TYPE_P (current_class_type))
              /* OK for C++11 lambdas.  */;
            else if (cxx_dialect < cxx14)

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

* [Bug c++/98441] [11 Regression] member function pointer incorrectly parsed as having trailing return type
  2020-12-25  0:24 [Bug c++/98441] New: member function pointer incorrectly parsed as having trailing return type daniel.santos at pobox dot com
                   ` (7 preceding siblings ...)
  2021-01-05 23:11 ` mpolacek at gcc dot gnu.org
@ 2021-01-07 21:20 ` cvs-commit at gcc dot gnu.org
  2021-01-07 21:23 ` mpolacek at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-01-07 21:20 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:2f359597e49a15a2aef8f83ea7a14649854334cb

commit r11-6531-g2f359597e49a15a2aef8f83ea7a14649854334cb
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue Jan 5 19:17:10 2021 -0500

    c++: Fix thinko in auto return type checking [PR98441]

    This fixes a thinko in my r11-2085 patch: when I said "But only give the
    !late_return_type errors when funcdecl_p, to accept e.g. auto (*fp)() = f;
    in C++11" I should've done this, otherwise we give bogus errors mentioning
    "function with trailing return type" when there is none.

    gcc/cp/ChangeLog:

            PR c++/98441
            * decl.c (grokdeclarator): Move the !funcdecl_p check inside the
            !late_return_type block.

    gcc/testsuite/ChangeLog:

            PR c++/98441
            * g++.dg/cpp0x/auto55.C: New test.

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

* [Bug c++/98441] [11 Regression] member function pointer incorrectly parsed as having trailing return type
  2020-12-25  0:24 [Bug c++/98441] New: member function pointer incorrectly parsed as having trailing return type daniel.santos at pobox dot com
                   ` (8 preceding siblings ...)
  2021-01-07 21:20 ` cvs-commit at gcc dot gnu.org
@ 2021-01-07 21:23 ` mpolacek at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-01-07 21:23 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #10 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.  Thanks for the report.

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

end of thread, other threads:[~2021-01-07 21:23 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-25  0:24 [Bug c++/98441] New: member function pointer incorrectly parsed as having trailing return type daniel.santos at pobox dot com
2020-12-25  0:29 ` [Bug c++/98441] " daniel.santos at pobox dot com
2020-12-27 20:23 ` [Bug c++/98441] [10/11 Regression] " redi at gcc dot gnu.org
2020-12-27 20:26 ` [Bug c++/98441] [11 " redi at gcc dot gnu.org
2020-12-29  9:07 ` daniel.santos at pobox dot com
2020-12-29 10:17 ` redi at gcc dot gnu.org
2020-12-29 18:19 ` daniel.santos at pobox dot com
2020-12-31 19:17 ` mpolacek at gcc dot gnu.org
2021-01-05 23:11 ` mpolacek at gcc dot gnu.org
2021-01-07 21:20 ` cvs-commit at gcc dot gnu.org
2021-01-07 21:23 ` 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).