[pushed] c++: constexpr class access in generic lambda [PR126754]
Jason Merrill <[email protected]>
| Newsgroups | gmane.comp.gcc.patches |
|---|---|
| Message-ID | <[email protected]> |
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
We don't want to see TARGET_EXPR in template trees because it's an
implementation detail, not a representation of the source. But constant
evaluation normally represents a constant class value with a TARGET_EXPR.
Let's not do the latter in a template.
PR c++/126754
gcc/cp/ChangeLog:
* constexpr.cc (cxx_eval_outermost_constant_expr): Don't
wrap in TARGET_EXPR when processing_template_decl.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/constexpr-lambda2.C: New test.
---
gcc/cp/constexpr.cc | 3 +++
gcc/testsuite/g++.dg/cpp1y/constexpr-lambda2.C | 11 +++++++++++
2 files changed, 14 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-lambda2.C
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index e16c878d725..c9ebc0027b7 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -11288,6 +11288,9 @@ cxx_eval_outermost_constant_expr (tree t, bool allow_non_constant,
/* Don't add a TARGET_EXPR if our argument didn't have one. */;
else if (TREE_CODE (t) == TARGET_EXPR && TARGET_EXPR_CLEANUP (t))
r = get_target_expr (r);
+ else if (processing_template_decl)
+ /* Don't insert TARGET_EXPR in template trees. */
+ return r;
else
{
r = get_target_expr (r, tf_warning_or_error | tf_no_cleanup);
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-lambda2.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-lambda2.C
new file mode 100644
index 00000000000..1ad31f83fc6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-lambda2.C
@@ -0,0 +1,11 @@
+// PR c++/126754
+// { dg-do compile { target c++14 } }
+
+struct S { int i; };
+int main() {
+ constexpr S a{1};
+ const auto f = [](auto b) {
+ return 1 - a.i; // this expression must be independent of b in order to trigger the crash
+ };
+ return f(0);
+}
base-commit: 34fd4c49fbe6ff643fc6f5f2cccca03c86535ee0
--
2.55.0