public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Constexpr fold even some TREE_CONSTANT ctors (PR c++/87934)
@ 2018-12-18 20:45 Jakub Jelinek
  2018-12-18 22:40 ` Jason Merrill
  0 siblings, 1 reply; 6+ messages in thread
From: Jakub Jelinek @ 2018-12-18 20:45 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-12-20 16:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-18 20:45 [C++ PATCH] Constexpr fold even some TREE_CONSTANT ctors (PR c++/87934) Jakub Jelinek
2018-12-18 22:40 ` Jason Merrill
2018-12-18 23:19   ` Jakub Jelinek
2018-12-19  3:28     ` Jason Merrill
2018-12-19 23:14       ` Jakub Jelinek
2018-12-20 16:01         ` 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).