summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-02-26 09:02:05 +0100
committerJakub Jelinek <jakub@redhat.com>2020-02-26 09:02:05 +0100
commitf4335f978249a2991620f38e118adf790e677968 (patch)
tree1556b4ba084748466bc575991af9c141bd82a7c1
parentf52ec6bc163af837cd13e234b7c2eab6bc456e12 (diff)
c++: Fix rejects-valid bug in cxx_eval_outermost_constant_expr [PR93905]
The following testcase is rejected in 8.3, but was accepted in 8.2 and is in 9.x. This started with my PR87934 * constexpr.c (cxx_eval_constant_expression) <case CONSTRUCTOR>: Do re-process TREE_CONSTANT CONSTRUCTORs if they aren't reduced constant expressions. backport, where the NSDMI CONSTRUCTOR that contains CONST_DECLs is now constexpr evaluated so that it doesn't contain them. The difference from 9.x is that 9.x doesn't call get_target_expr if we got a CONSTRUCTOR for a class type for something that has been originally a CONSTRUCTOR too. This patch cherry-picks just that hunk of the r9-3835 change. 2020-02-26 Jakub Jelinek <jakub@redhat.com> PR c++/93905 Backported from mainline 2018-11-04 Jason Merrill <jason@redhat.com> * constexpr.c (cxx_eval_outermost_constant_expr): Don't wrap a CONSTRUCTOR if one was passed in. * g++.dg/cpp0x/pr93905.C: New test.
-rw-r--r--gcc/cp/ChangeLog9
-rw-r--r--gcc/cp/constexpr.c6
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/pr93905.C18
4 files changed, 34 insertions, 4 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 1b5e2bb2cdeb..40a1f39dfb07 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,12 @@
+2020-02-26 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/93905
+ Backported from mainline
+ 2018-11-04 Jason Merrill <jason@redhat.com>
+
+ * constexpr.c (cxx_eval_outermost_constant_expr): Don't wrap a
+ CONSTRUCTOR if one was passed in.
+
2020-02-26 Marek Polacek <polacek@redhat.com>
PR c++/90998 - ICE with copy elision in init by ctor and -Wconversion.
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 5fb0623ed580..bebe72e4db91 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -4998,15 +4998,13 @@ cxx_eval_outermost_constant_expr (tree t, bool allow_non_constant,
if (TREE_CODE (t) == TARGET_EXPR
&& TARGET_EXPR_INITIAL (t) == r)
return t;
- else
+ else if (TREE_CODE (t) != CONSTRUCTOR)
{
r = get_target_expr (r);
TREE_CONSTANT (r) = true;
- return r;
}
}
- else
- return r;
+ return r;
}
/* Returns true if T is a valid subexpression of a constant expression,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 440e35ad3414..ac16b95a8df5 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-02-26 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/93905
+ * g++.dg/cpp0x/pr93905.C: New test.
+
2020-02-26 Marek Polacek <polacek@redhat.com>
PR c++/90998 - ICE with copy elision in init by ctor and -Wconversion.
diff --git a/gcc/testsuite/g++.dg/cpp0x/pr93905.C b/gcc/testsuite/g++.dg/cpp0x/pr93905.C
new file mode 100644
index 000000000000..81c6266a795a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/pr93905.C
@@ -0,0 +1,18 @@
+// PR c++/93905
+// { dg-do compile { target c++11 } }
+
+enum class E { VALUE };
+
+struct B {
+ E e{E::VALUE};
+protected:
+ ~B () = default;
+};
+
+struct D : B {};
+
+int
+main ()
+{
+ D d{};
+}