* [PATCH] c++: Fix thinko in auto return type checking [PR98441]
@ 2021-01-06 0:31 Marek Polacek
2021-01-07 21:12 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2021-01-06 0:31 UTC (permalink / raw)
To: Jason Merrill, GCC Patches
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.
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
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.
---
gcc/cp/decl.c | 8 +++++---
gcc/testsuite/g++.dg/cpp0x/auto55.C | 13 +++++++++++++
2 files changed, 18 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp0x/auto55.C
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index bf6f12c26a0..1a114a2e2d0 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 00000000000..5bd32ac890d
--- /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;
+}
base-commit: ad92bf4b165935b58195825dc8f089f53fd2710b
--
2.29.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: Fix thinko in auto return type checking [PR98441]
2021-01-06 0:31 [PATCH] c++: Fix thinko in auto return type checking [PR98441] Marek Polacek
@ 2021-01-07 21:12 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2021-01-07 21:12 UTC (permalink / raw)
To: Marek Polacek, GCC Patches
On 1/5/21 7:31 PM, Marek Polacek wrote:
> 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.
>
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
OK.
> 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.
> ---
> gcc/cp/decl.c | 8 +++++---
> gcc/testsuite/g++.dg/cpp0x/auto55.C | 13 +++++++++++++
> 2 files changed, 18 insertions(+), 3 deletions(-)
> create mode 100644 gcc/testsuite/g++.dg/cpp0x/auto55.C
>
> diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
> index bf6f12c26a0..1a114a2e2d0 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 00000000000..5bd32ac890d
> --- /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;
> +}
>
> base-commit: ad92bf4b165935b58195825dc8f089f53fd2710b
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-01-07 21:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-06 0:31 [PATCH] c++: Fix thinko in auto return type checking [PR98441] Marek Polacek
2021-01-07 21:12 ` Jason Merrill
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).