public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-6716] c++: maybe_constant_init and unevaluated operands [PR109030]
@ 2023-03-16 18:47 Patrick Palka
0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2023-03-16 18:47 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:31cdfdef04701e10cffcec4578b2337684f0e4bc
commit r13-6716-g31cdfdef04701e10cffcec4578b2337684f0e4bc
Author: Patrick Palka <ppalka@redhat.com>
Date: Thu Mar 16 14:47:43 2023 -0400
c++: maybe_constant_init and unevaluated operands [PR109030]
This testcase in this PR (already fixed by r13-6526-ge4692319fd5fc7)
demonstrates that maybe_constant_init can be called on an unevaluated
operand (e.g. from massage_init_elt) so this entry point should also
limit constant evaluation in that case, like maybe_constant_value does.
PR c++/109030
gcc/cp/ChangeLog:
* constexpr.cc (maybe_constant_init_1): For an unevaluated
non-manifestly-constant operand, don't constant evaluate
and instead call fold_to_constant as in maybe_constant_value.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/constexpr-inst2.C: New test.
Diff:
---
gcc/cp/constexpr.cc | 4 ++++
gcc/testsuite/g++.dg/cpp2a/constexpr-inst2.C | 12 ++++++++++++
2 files changed, 16 insertions(+)
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index abf6ee560c5..3de60cfd0f8 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -8796,6 +8796,10 @@ maybe_constant_init_1 (tree t, tree decl, bool allow_non_constant,
&& (TREE_STATIC (decl) || DECL_EXTERNAL (decl)));
if (is_static)
manifestly_const_eval = true;
+
+ if (cp_unevaluated_operand && !manifestly_const_eval)
+ return fold_to_constant (t);
+
t = cxx_eval_outermost_constant_expr (t, allow_non_constant, !is_static,
mce_value (manifestly_const_eval),
false, decl);
diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-inst2.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-inst2.C
new file mode 100644
index 00000000000..7676b625321
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-inst2.C
@@ -0,0 +1,12 @@
+// { dg-do compile { target c++11 } }
+
+struct __as_receiver {
+ int empty_env;
+};
+
+template<class T>
+constexpr int f(T t) {
+ return t.fail;
+};
+
+using type = decltype(__as_receiver{f(0)}); // OK, f<int> not instantiated
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-03-16 18:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-16 18:47 [gcc r13-6716] c++: maybe_constant_init and unevaluated operands [PR109030] Patrick Palka
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).