c++: Fix consteval operator handling.
authorJason Merrill <jason@redhat.com>
Tue, 16 Jun 2020 04:19:53 +0000 (00:19 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 17 Jun 2020 19:08:42 +0000 (15:08 -0400)
We were crashing trying to find the CALL_EXPR in the result of a call to a
consteval operator.

gcc/cp/ChangeLog:

* call.c (build_new_op_1): Don't look for a CALL_EXPR when
calling a consteval function.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/consteval17.C: New test.

gcc/cp/call.c
gcc/testsuite/g++.dg/cpp2a/consteval17.C [new file with mode: 0644]

index 1d95bd2d07bed5826772fcb9f4fb94355f445bf1..5382b7620dcf57db553b4715b84a74133d42ccba 100644 (file)
@@ -6341,7 +6341,7 @@ build_new_op_1 (const op_location_t &loc, enum tree_code code, int flags,
              result = build_over_call (cand, LOOKUP_NORMAL, ocomplain);
            }
 
-         if (trivial_fn_p (cand->fn))
+         if (trivial_fn_p (cand->fn) || DECL_IMMEDIATE_FUNCTION_P (cand->fn))
            /* There won't be a CALL_EXPR.  */;
          else if (result && result != error_mark_node)
            {
diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval17.C b/gcc/testsuite/g++.dg/cpp2a/consteval17.C
new file mode 100644 (file)
index 0000000..6af39aa
--- /dev/null
@@ -0,0 +1,11 @@
+// { dg-do compile { target c++20 } }
+
+struct A
+{
+  consteval int operator+() { return 42; }
+};
+
+int main()
+{
+  +A();
+}