This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Constexpr fold even some TREE_CONSTANT ctors (PR c++/87934)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 18 Dec 2018 21:45:17 +0100
- Subject: [C++ PATCH] Constexpr fold even some TREE_CONSTANT ctors (PR c++/87934)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
The following testcase FAILs, because parsing creates a TREE_CONSTANT
CONSTRUCTOR that contains CONST_DECL elts. cp_fold_r can handle that,
but constexpr evaluation doesn't touch those CONSTRUCTORs.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?
2018-12-18 Jakub Jelinek <jakub@redhat.com>
PR c++/87934
* constexpr.c (cxx_eval_constant_expression) <case CONSTRUCTOR>: Do
re-process TREE_CONSTANT CONSTRUCTORs if they aren't reduced constant
expressions.
* g++.dg/cpp0x/constexpr-87934.C: New test.
--- gcc/cp/constexpr.c.jj 2018-12-12 23:43:57.263128844 +0100
+++ gcc/cp/constexpr.c 2018-12-18 14:43:33.460553853 +0100
@@ -4681,7 +4681,7 @@ cxx_eval_constant_expression (const cons
break;
case CONSTRUCTOR:
- if (TREE_CONSTANT (t))
+ if (TREE_CONSTANT (t) && reduced_constant_expression_p (t))
{
/* Don't re-process a constant CONSTRUCTOR, but do fold it to
VECTOR_CST if applicable. */
--- gcc/testsuite/g++.dg/cpp0x/constexpr-87934.C.jj 2018-12-18 15:05:56.318886878 +0100
+++ gcc/testsuite/g++.dg/cpp0x/constexpr-87934.C 2018-12-18 15:02:10.652524999 +0100
@@ -0,0 +1,9 @@
+// PR c++/87934
+// { dg-do compile { target c++11 } }
+
+struct Foo
+{
+ enum { BAR } bar = BAR;
+};
+
+constexpr Foo foo{};
Jakub