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
Also, I build gcc with: -O42 -ffast-math -ffuzzy-dice -felide-function-bodies -pipe-clogged but that shouldn't make a difference.
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;
(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).
Created attachment 49850 [details] 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))
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).
(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!
Mine.
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)
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.
Fixed. Thanks for the report.