* [PATCH] c++: decltype of non-dependent call of class type [PR105386]
@ 2022-04-26 13:45 Patrick Palka
2022-04-26 14:33 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2022-04-26 13:45 UTC (permalink / raw)
To: gcc-patches
We need to pass tf_decltype when instantiating a non-dependent decltype
operand, like tsubst does in the dependent case, so that we avoid
materializing a temporary for a prvalue operand.
Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk/11?
PR c++/105386
gcc/cp/ChangeLog:
* semantics.cc (finish_decltype_type): Pass tf_decltype to
instantiate_non_dependent_expr_sfinae.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/decltype81.C: New test.
---
gcc/cp/semantics.cc | 2 +-
gcc/testsuite/g++.dg/cpp0x/decltype81.C | 15 +++++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/cpp0x/decltype81.C
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index f08c0b6281f..ab48f11c9be 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -11252,7 +11252,7 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
}
else if (processing_template_decl)
{
- expr = instantiate_non_dependent_expr_sfinae (expr, complain);
+ expr = instantiate_non_dependent_expr_sfinae (expr, complain|tf_decltype);
if (expr == error_mark_node)
return error_mark_node;
/* Keep processing_template_decl cleared for the rest of the function
diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype81.C b/gcc/testsuite/g++.dg/cpp0x/decltype81.C
new file mode 100644
index 00000000000..7d25db39d9c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/decltype81.C
@@ -0,0 +1,15 @@
+// PR c++/105386
+// { dg-do compile { target c++11 } }
+
+template<class T> struct NoInst {
+ static_assert(sizeof(T) == 9999, "NoInst instantiated");
+};
+
+template<class T> NoInst<T> f(T);
+
+template<class>
+struct A {
+ using type = decltype(f(0));
+};
+
+A<int> a;
--
2.36.0.rc2.10.g1ac7422e39
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: decltype of non-dependent call of class type [PR105386]
2022-04-26 13:45 [PATCH] c++: decltype of non-dependent call of class type [PR105386] Patrick Palka
@ 2022-04-26 14:33 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2022-04-26 14:33 UTC (permalink / raw)
To: Patrick Palka, gcc-patches
On 4/26/22 09:45, Patrick Palka wrote:
> We need to pass tf_decltype when instantiating a non-dependent decltype
> operand, like tsubst does in the dependent case, so that we avoid
> materializing a temporary for a prvalue operand.
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk/11?
OK.
> PR c++/105386
>
> gcc/cp/ChangeLog:
>
> * semantics.cc (finish_decltype_type): Pass tf_decltype to
> instantiate_non_dependent_expr_sfinae.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/cpp0x/decltype81.C: New test.
> ---
> gcc/cp/semantics.cc | 2 +-
> gcc/testsuite/g++.dg/cpp0x/decltype81.C | 15 +++++++++++++++
> 2 files changed, 16 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/g++.dg/cpp0x/decltype81.C
>
> diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
> index f08c0b6281f..ab48f11c9be 100644
> --- a/gcc/cp/semantics.cc
> +++ b/gcc/cp/semantics.cc
> @@ -11252,7 +11252,7 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
> }
> else if (processing_template_decl)
> {
> - expr = instantiate_non_dependent_expr_sfinae (expr, complain);
> + expr = instantiate_non_dependent_expr_sfinae (expr, complain|tf_decltype);
> if (expr == error_mark_node)
> return error_mark_node;
> /* Keep processing_template_decl cleared for the rest of the function
> diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype81.C b/gcc/testsuite/g++.dg/cpp0x/decltype81.C
> new file mode 100644
> index 00000000000..7d25db39d9c
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp0x/decltype81.C
> @@ -0,0 +1,15 @@
> +// PR c++/105386
> +// { dg-do compile { target c++11 } }
> +
> +template<class T> struct NoInst {
> + static_assert(sizeof(T) == 9999, "NoInst instantiated");
> +};
> +
> +template<class T> NoInst<T> f(T);
> +
> +template<class>
> +struct A {
> + using type = decltype(f(0));
> +};
> +
> +A<int> a;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-04-26 14:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-26 13:45 [PATCH] c++: decltype of non-dependent call of class type [PR105386] Patrick Palka
2022-04-26 14:33 ` 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).