From 9bf6c63da9ff140bb37d957ad1252848e2df28ef Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Fri, 23 Aug 2019 23:24:46 +0000 Subject: [PATCH] PR c++/91521 - wrong error with operator->. * decl.c (grokdeclarator): Return error_mark_node for an invalid trailing return type. * g++.dg/parse/operator8.C: New test. From-SVN: r274891 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/decl.c | 2 ++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/parse/operator8.C | 13 +++++++++++++ 4 files changed, 24 insertions(+) create mode 100644 gcc/testsuite/g++.dg/parse/operator8.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5a59f984af0..8eebf894f45 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2019-08-23 Marek Polacek + PR c++/91521 - wrong error with operator->. + * decl.c (grokdeclarator): Return error_mark_node for an invalid + trailing return type. + PR c++/79817 - attribute deprecated on namespace. * cp-tree.h (cp_warn_deprecated_use_scopes): Declare. * decl.c (grokdeclarator): Call cp_warn_deprecated_use_scopes. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index cb5571e4f24..9f7923871db 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -11549,6 +11549,8 @@ grokdeclarator (const cp_declarator *declarator, else if (late_return_type && sfk != sfk_conversion) { + if (late_return_type == error_mark_node) + return error_mark_node; if (cxx_dialect < cxx11) /* Not using maybe_warn_cpp0x because this should always be an error. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f657cfa1a63..2162fcf40f4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-08-23 Marek Polacek + + PR c++/91521 - wrong error with operator->. + * g++.dg/parse/operator8.C: New test. + 2019-08-23 Segher Boessenkool PR target/91481 diff --git a/gcc/testsuite/g++.dg/parse/operator8.C b/gcc/testsuite/g++.dg/parse/operator8.C new file mode 100644 index 00000000000..c5ee3eb934a --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/operator8.C @@ -0,0 +1,13 @@ +// PR c++/91521 - wrong error with operator->. +// { dg-do compile } + +struct foo { + int bar() { return 0; } + foo* operator->() { return this; } +}; + +int main() +{ + int pt(foo()->bar()); + return pt; +} -- 2.30.2