Patchwork C++ PATCH for c++/55419 (TREE_CONSTANT on TARGET_EXPR)

login
register
mail settings
Submitter Jason Merrill
Date Dec. 8, 2012, 12:38 a.m.
Message ID <50C28BFA.5060705@redhat.com>
Download mbox | patch
Permalink /patch/204641/
State New
Headers show

Comments

Jason Merrill - Dec. 8, 2012, 12:38 a.m.
The analysis of 55419 pointed out the conflict in a TARGET_EXPR having 
both TREE_SIDE_EFFECTS and TREE_CONSTANT set.  After reading that I 
decided to stop setting TREE_CONSTANT on the TARGET_EXPR and do the 
necessary work to adjust for that.  And then was surprised to find that 
no additional work was necessary.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.7.

Patch

commit b0f1533a6e7981e5ae12809a60f7b4a96221ff13
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Dec 7 10:42:01 2012 -0500

    	PR c++/55419
    	* tree.c (build_target_expr): Don't set TREE_CONSTANT.

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index ca82f75..963bb1b 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -329,8 +329,6 @@  build_target_expr (tree decl, tree value, tsubst_flags_t complain)
      side-effects, then the optimizer should be able to get rid of
      whatever code is generated anyhow.  */
   TREE_SIDE_EFFECTS (t) = 1;
-  if (literal_type_p (type))
-    TREE_CONSTANT (t) = TREE_CONSTANT (value);
 
   return t;
 }
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist6.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist6.C
new file mode 100644
index 0000000..6b822a1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist6.C
@@ -0,0 +1,27 @@ 
+// PR c++/55419
+// { dg-options -std=c++11 }
+
+struct P
+{
+  P () = default;
+  explicit constexpr P (int x) : p (x) {}
+  int p;
+};
+
+struct Q
+{
+  constexpr Q () : q (0x7f) {}
+  int q;
+};
+
+struct R
+{
+  Q q;
+  P p;
+};
+
+void
+foo (R *x)
+{
+  *x = {};
+}