PR c++/91521 - wrong error with operator->.
authorMarek Polacek <polacek@redhat.com>
Fri, 23 Aug 2019 23:24:46 +0000 (23:24 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 23 Aug 2019 23:24:46 +0000 (23:24 +0000)
* 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
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/operator8.C [new file with mode: 0644]

index 5a59f984af0355b90048f9ac57bddd4d17f0d3c9..8eebf894f45bd8d7d1411a314df78417e215acc4 100644 (file)
@@ -1,5 +1,9 @@
 2019-08-23  Marek Polacek  <polacek@redhat.com>
 
+       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.
index cb5571e4f24465c34717d2a9c3f8bc684bce49e2..9f7923871db42feb37dafcf84832789dc96ba066 100644 (file)
@@ -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.  */
index f657cfa1a632843801acbdc94c65e10f00e3662f..2162fcf40f43efa5083ba32d54863765e858a238 100644 (file)
@@ -1,3 +1,8 @@
+2019-08-23  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/91521 - wrong error with operator->.
+       * g++.dg/parse/operator8.C: New test.
+
 2019-08-23  Segher Boessenkool  <segher@kernel.crashing.org>
 
        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 (file)
index 0000000..c5ee3eb
--- /dev/null
@@ -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;
+}