* [PATCH] c++: non-dependent call to consteval operator [PR105912]
@ 2022-07-12 1:27 Patrick Palka
2022-07-12 15:51 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2022-07-12 1:27 UTC (permalink / raw)
To: gcc-patches
Here we were 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
called function is consteval. This patch fixes this by checking the
result of extract_call_expr accordingly. (Note that we can't easily
check DECL_IMMEDIATE_FUNCTION_P here because we don't know which
function was selected by overload resolution from this call frame.)
Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK
for trunk/12?
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.
---
gcc/cp/pt.cc | 10 +++++----
gcc/testsuite/g++.dg/cpp2a/consteval31.C | 26 ++++++++++++++++++++++++
2 files changed, 32 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp2a/consteval31.C
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 232964c2831..8a6ae5c42fe 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -21207,10 +21207,12 @@ tsubst_copy_and_build (tree 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;
+ }
}
}
diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval31.C b/gcc/testsuite/g++.dg/cpp2a/consteval31.C
new file mode 100644
index 00000000000..85a4d1794e5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/consteval31.C
@@ -0,0 +1,26 @@
+// 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>();
--
2.37.0.3.g30cc8d0f14
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: non-dependent call to consteval operator [PR105912]
2022-07-12 1:27 [PATCH] c++: non-dependent call to consteval operator [PR105912] Patrick Palka
@ 2022-07-12 15:51 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2022-07-12 15:51 UTC (permalink / raw)
To: Patrick Palka, gcc-patches
On 7/11/22 21:27, Patrick Palka wrote:
> Here we were 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
> called function is consteval. This patch fixes this by checking the
> result of extract_call_expr accordingly. (Note that we can't easily
> check DECL_IMMEDIATE_FUNCTION_P here because we don't know which
> function was selected by overload resolution from this call frame.)
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK
> for trunk/12?
>
> 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.
> ---
> gcc/cp/pt.cc | 10 +++++----
> gcc/testsuite/g++.dg/cpp2a/consteval31.C | 26 ++++++++++++++++++++++++
> 2 files changed, 32 insertions(+), 4 deletions(-)
> create mode 100644 gcc/testsuite/g++.dg/cpp2a/consteval31.C
>
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 232964c2831..8a6ae5c42fe 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -21207,10 +21207,12 @@ tsubst_copy_and_build (tree t,
> bool rev = CALL_EXPR_REVERSE_ARGS (t);
> if (op || ord || rev)
> {
I'd drop this pair of braces. OK either way.
> - 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;
> + }
> }
> }
>
> diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval31.C b/gcc/testsuite/g++.dg/cpp2a/consteval31.C
> new file mode 100644
> index 00000000000..85a4d1794e5
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/consteval31.C
> @@ -0,0 +1,26 @@
> +// 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>();
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-07-12 15:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-12 1:27 [PATCH] c++: non-dependent call to consteval operator [PR105912] Patrick Palka
2022-07-12 15:51 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).