Skip to content
Snippets Groups Projects
Commit f70c1852 authored by Patrick Palka's avatar Patrick Palka
Browse files

c++: non-dependent call to consteval operator [PR105912]

Here we're crashing when substituting a non-dependent call to a
consteval operator, whose CALL_EXPR_OPERATOR_SYNTAX flag we try to
propagate to the result, but the result isn't a CALL_EXPR since the
selected function is consteval.  This patch fixes this by checking the
result of extract_call_expr accordingly.  (Note that we can't check
DECL_IMMEDIATE_FUNCTION_P here because we don't know which function was
selected by overload resolution from here.)

	PR c++/105912

gcc/cp/ChangeLog:

	* pt.cc (tsubst_copy_and_build) <case CALL_EXPR>: Guard against
	NULL_TREE extract_call_expr result.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/consteval31.C: New test.
parent f07778f6
No related branches found
No related tags found
No related merge requests found
......@@ -21206,12 +21206,12 @@ tsubst_copy_and_build (tree t,
bool ord = CALL_EXPR_ORDERED_ARGS (t);
bool rev = CALL_EXPR_REVERSE_ARGS (t);
if (op || ord || rev)
{
function = extract_call_expr (ret);
CALL_EXPR_OPERATOR_SYNTAX (function) = op;
CALL_EXPR_ORDERED_ARGS (function) = ord;
CALL_EXPR_REVERSE_ARGS (function) = rev;
}
if (tree call = extract_call_expr (ret))
{
CALL_EXPR_OPERATOR_SYNTAX (call) = op;
CALL_EXPR_ORDERED_ARGS (call) = ord;
CALL_EXPR_REVERSE_ARGS (call) = rev;
}
}
 
RETURN (ret);
......
// PR c++/105912
// { dg-do compile { target c++20 } }
struct A {
consteval A operator+() {
return {};
}
};
consteval A operator~(A) {
return {};
}
consteval A operator+(A, A) {
return {};
}
template<class>
void f() {
A a;
~a;
a + a;
+a;
}
template void f<int>();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment