diff mbox

C++ PATCH for c++/56614 (bogus error with initializer list in default argument)

Message ID 5141CBA3.6010601@redhat.com
State New
Headers show

Commit Message

Jason Merrill March 14, 2013, 1:07 p.m. UTC
Removing the DECL_ARTIFICIAL check meant warning about TARGET_EXPR 
temporaries, which we don't want; instead, let's check for 'this' directly.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit 2139bd24c219d1b665738d2b630e90dd25cc9cd1
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Mar 14 08:35:24 2013 -0400

    	PR c++/56614
    	* decl.c (local_variable_p_walkfn): Check DECL_ARTIFICIAL again.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 92114ff..0e66840 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -10803,9 +10803,8 @@  static tree
 local_variable_p_walkfn (tree *tp, int *walk_subtrees,
 			 void * /*data*/)
 {
-  /* Check DECL_NAME to avoid including temporaries.  We don't check
-     DECL_ARTIFICIAL because we do want to complain about 'this'.  */
-  if (local_variable_p (*tp) && DECL_NAME (*tp))
+  if (local_variable_p (*tp)
+      && (!DECL_ARTIFICIAL (*tp) || DECL_NAME (*tp) == this_identifier))
     return *tp;
   else if (TYPE_P (*tp))
     *walk_subtrees = 0;
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-defarg1.C b/gcc/testsuite/g++.dg/cpp0x/initlist-defarg1.C
new file mode 100644
index 0000000..45eb2d5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-defarg1.C
@@ -0,0 +1,36 @@ 
+// PR c++/56614
+// { dg-require-effective-target c++11 }
+
+#include <initializer_list>
+
+namespace std
+{
+    template<typename T>
+        struct allocator
+        { };
+
+    template<typename T, typename Alloc = std::allocator<T> >
+        struct vector
+        {
+            vector(std::initializer_list<T>, const Alloc& = Alloc()) { }
+        };
+}
+
+void func() { }
+
+enum E { ee };
+
+struct C
+{
+    template<typename T>
+        C(T, std::vector<E> = std::vector<E>({ ee }))
+        { }
+};
+
+struct G
+{
+    void gen()
+    {
+        C c(&func);
+    }
+};