c++: decltype of invalid non-dependent expr [PR57943]
authorPatrick Palka <ppalka@redhat.com>
Fri, 15 May 2020 22:51:11 +0000 (18:51 -0400)
committerPatrick Palka <ppalka@redhat.com>
Fri, 15 May 2020 22:51:11 +0000 (18:51 -0400)
We sometimes fail to reject an invalid non-dependent operand to decltype
when inside a template, because finish_decltype_type resolves the
decltype to the TREE_TYPE of the operand before we ever instantiate and
fully process the operand.  Fix this by adding a call to
instantiate_non_dependent_expr_sfinae in finish_decltype_type.

gcc/cp/ChangeLog:

PR c++/57943
* semantics.c (finish_decltype_type): Call
instantiate_non_dependent_expr_sfinae on the expression.

gcc/testsuite/ChangeLog:

PR c++/57943
* g++.dg/cpp0x/decltype76.C: New test.

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/decltype76.C [new file with mode: 0644]

index acd2d7be844e879b54da958efa1bd57e8c3bb2de..4b9fc52b6e3138a19a70acca7288e4a6a5a88891 100644 (file)
@@ -1,3 +1,9 @@
+2020-05-16  Patrick Palka  <ppalka@redhat.com>
+
+       PR c++/57943
+       * semantics.c (finish_decltype_type): Call
+       instantiate_non_dependent_expr_sfinae on the expression.
+
 2020-05-15  Patrick Palka  <ppalka@redhat.com>
 
        Revert:
index d90816eabc94ef1c2f636ae69c4a008c6da28e80..64587c791c67950f1ca85587e9d7575f7068dfc1 100644 (file)
@@ -9746,6 +9746,14 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
 
       return type;
     }
+  else if (processing_template_decl)
+    {
+      ++cp_unevaluated_operand;
+      expr = instantiate_non_dependent_expr_sfinae (expr, complain);
+      --cp_unevaluated_operand;
+      if (expr == error_mark_node)
+       return error_mark_node;
+    }
 
   /* The type denoted by decltype(e) is defined as follows:  */
 
index 875ac82fb3407c494fdcf5edfe445b3f134b8b07..a7f777118f2614e7342399c3c941669f97985697 100644 (file)
@@ -1,3 +1,8 @@
+2020-05-16  Patrick Palka  <ppalka@redhat.com>
+
+       PR c++/57943
+       * g++.dg/cpp0x/decltype76.C: New test.
+
 2020-05-15  Jason Merrill  <jason@redhat.com>
 
        * g++.dg/coroutines/coro.h: Always #include <utility>.
diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype76.C b/gcc/testsuite/g++.dg/cpp0x/decltype76.C
new file mode 100644 (file)
index 0000000..239fe6d
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c+/57943
+// { dg-do compile { target c++11 } }
+
+struct a { };
+
+template <typename T = decltype (a(0))> // { dg-error "" }
+void f() { }