diff mbox

C++ PATCH for c++/57196 (wrong error with initializer-list constructor)

Message ID 518D0447.4010002@redhat.com
State New
Headers show

Commit Message

Jason Merrill May 10, 2013, 2:29 p.m. UTC
When I added the check for instantiation-dependent expressions, I 
treated statement-expressions and some qualified-ids as 
instantiation-dependent even when they don't involve template 
parameters.  In this PR, that causes problems because array 
initialization expands into a statement-expression via build_vec_init, 
and a sizeof-expression is not immediately folded, and then when we go 
to convert the sizeof to the appropriate type for the template non-type 
parameter, we call uses_template_parms, which pretends we're in a 
template, we look inside the sizeof and see the statement-expression, 
and decide that it's dependent.

The solution is not to pretend that we're in a template when deciding 
whether a template argument is dependent.

Tested x86_64-pc-linux-gnu, applying to trunk.  If no problems turn up, 
I'll apply it to 4.8 later as well.
diff mbox

Patch

commit 32bf8cd06a9d5e2ad4abd35ce3571457a071b27d
Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Fri May 10 14:17:45 2013 +0000

    	PR c++/57196
    	* pt.c (convert_template_argument): Use dependent_template_arg_p,
    	not uses_template_parms.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@198778 138bc75d-0d04-0410-961f-82ee72b054a4

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 0747de6..8f88b10 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -6368,7 +6368,8 @@  convert_template_argument (tree parm,
 	      val = error_mark_node;
 	    }
 	}
-      else if (!uses_template_parms (orig_arg) && !uses_template_parms (t))
+      else if (!dependent_template_arg_p (orig_arg)
+	       && !uses_template_parms (t))
 	/* We used to call digest_init here.  However, digest_init
 	   will report errors, which we don't want when complain
 	   is zero.  More importantly, digest_init will try too
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist70.C b/gcc/testsuite/g++.dg/cpp0x/initlist70.C
new file mode 100644
index 0000000..f215b9d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist70.C
@@ -0,0 +1,27 @@ 
+// PR c++/57196
+// { dg-require-effective-target c++11 }
+
+#include <initializer_list>
+
+template<class T>
+struct set {
+  set() = default;
+  set(std::initializer_list<T>){}
+};
+
+struct string {
+  string(const char*){}
+  ~string(){}
+};
+
+typedef decltype(sizeof(0)) size_t;
+
+template <size_t> struct EqHelper { };
+
+int IsNullLiteralHelper(...);
+
+void Fn() {
+  EqHelper<sizeof IsNullLiteralHelper(set<int>{1})>        eq1;  // ok
+  EqHelper<sizeof IsNullLiteralHelper(set<string>())>      eq2;  // ok
+  EqHelper<sizeof IsNullLiteralHelper(set<string>{"foo"})> eq3;  // error
+}
diff --git a/gcc/testsuite/g++.dg/template/crash106.C b/gcc/testsuite/g++.dg/template/crash106.C
index c2d117e..ebd47bc 100644
--- a/gcc/testsuite/g++.dg/template/crash106.C
+++ b/gcc/testsuite/g++.dg/template/crash106.C
@@ -10,3 +10,5 @@  struct A
 template<T N = 0, void (A::*)() = &A::foo<N> > struct B {}; // { dg-error "type|declared" }
 
 B<> b; // { dg-error "type|declaration" }
+
+// { dg-prune-output "could not convert" }
diff --git a/gcc/testsuite/g++.dg/template/crash112.C b/gcc/testsuite/g++.dg/template/crash112.C
index 919c887..ff35764 100644
--- a/gcc/testsuite/g++.dg/template/crash112.C
+++ b/gcc/testsuite/g++.dg/template/crash112.C
@@ -5,7 +5,7 @@  struct A
   template<typename> void foo() {}
 };
 
-template<void (A::*)()> struct B {}; // { dg-error "declaration" }
+template<void (A::*)()> struct B {};
 
 template<int> struct C
 {
@@ -13,3 +13,5 @@  template<int> struct C
 };
 
 C<0> c;
+
+// { dg-prune-output "could not convert" }
diff --git a/gcc/testsuite/g++.dg/template/dependent-args1.C b/gcc/testsuite/g++.dg/template/dependent-args1.C
index 0b197cf..a540e55 100644
--- a/gcc/testsuite/g++.dg/template/dependent-args1.C
+++ b/gcc/testsuite/g++.dg/template/dependent-args1.C
@@ -9,3 +9,5 @@  struct A
 template<int N, void (A::*)() = &A::foo<N> > struct B {};
 
 B<int> b; // { dg-error "type/value mismatch|expected a constant|invalid type" }
+
+// { dg-prune-output "could not convert" }