re PR c++/41997 ([C++0x] constant initializer_list not optimised)
authorJason Merrill <jason@redhat.com>
Sun, 14 Feb 2010 15:17:30 +0000 (10:17 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Sun, 14 Feb 2010 15:17:30 +0000 (10:17 -0500)
PR c++/41997
* semantics.c (finish_compound_literal): Use
cp_apply_type_quals_to_decl when creating a static variable.

From-SVN: r156760

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/initlist-opt.C [new file with mode: 0644]

index 7e37b69545bb8e41f229b7bbe9d1c3bcd506efa8..0b96f4c8fbf8647c7a1696421c5d8b6fc5fe2ad3 100644 (file)
@@ -1,3 +1,9 @@
+2010-02-14  Jason Merrill  <jason@redhat.com>
+
+       PR c++/41997
+       * semantics.c (finish_compound_literal): Use
+       cp_apply_type_quals_to_decl when creating a static variable.
+
 2010-02-12  Jason Merrill  <jason@redhat.com>
 
        PR c++/43024
index 985e2c0f4648c79ad6b0d359217937aed44fb7f9..90a76d9391cecc5aa96f53e9cf6cd010062d8ed1 100644 (file)
@@ -2257,6 +2257,7 @@ finish_compound_literal (tree type, tree compound_literal)
       tree decl = create_temporary_var (type);
       DECL_INITIAL (decl) = compound_literal;
       TREE_STATIC (decl) = 1;
+      cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
       decl = pushdecl_top_level (decl);
       DECL_NAME (decl) = make_anon_name ();
       SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
index 157d79cb4c8abf882cf383bf5299dca60097f58a..891e33d5e5a78efe6155713bdf92036f14f4ba26 100644 (file)
@@ -1,3 +1,8 @@
+2010-02-14  Jason Merrill  <jason@redhat.com>
+
+       PR c++/41997
+       * g++.dg/cpp0x/initlist-opt.C: New.
+
 2010-02-13  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/41113
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-opt.C b/gcc/testsuite/g++.dg/cpp0x/initlist-opt.C
new file mode 100644 (file)
index 0000000..f515ed8
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/41997
+// { dg-options "-std=c++0x -O2 -fdump-tree-optimized" }
+// { dg-final { scan-tree-dump-not "_0" "optimized" } }
+// { dg-final { cleanup-tree-dump "optimized" } }
+
+#include <initializer_list>
+
+int max_val(std::initializer_list<int> il)
+{
+        int i = *(il.begin());
+        int j = *(il.begin() + 1);
+        return (i > j ? i : j);
+}
+
+int main(void)
+{
+        return max_val({1,2});
+}
+