diff options
author | Marek Polacek <polacek@redhat.com> | 2021-01-05 19:17:10 -0500 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2021-01-07 16:19:29 -0500 |
commit | 2f359597e49a15a2aef8f83ea7a14649854334cb (patch) | |
tree | b68dbb6ee06ac4adb412fa526bc0d06a21a7e9ef | |
parent | 6c59b8a93cf4784e3e3137416a3d32a1ecc8e00b (diff) | |
download | gcc-2f359597e49a15a2aef8f83ea7a14649854334cb.zip gcc-2f359597e49a15a2aef8f83ea7a14649854334cb.tar.gz gcc-2f359597e49a15a2aef8f83ea7a14649854334cb.tar.bz2 |
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.
-rw-r--r-- | gcc/cp/decl.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/auto55.C | 13 |
2 files changed, 18 insertions, 3 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index bf6f12c..1a114a2 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -12241,10 +12241,12 @@ 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 - && LAMBDA_TYPE_P (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) { diff --git a/gcc/testsuite/g++.dg/cpp0x/auto55.C b/gcc/testsuite/g++.dg/cpp0x/auto55.C new file mode 100644 index 0000000..5bd32ac --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/auto55.C @@ -0,0 +1,13 @@ +// PR c++/98441 +// { dg-do compile { target c++11 } } + +struct a { + int& mfn(); +}; + +void fn() +{ + int& (a::*myvar1)(void) = &a::mfn; + auto& (a::*myvar2)(void) = &a::mfn; + auto (a::*myvar3)(void) = &a::mfn; +} |