Patchwork C++ PATCH for c++/48261 (ICE with non-template used as template)

login
register
mail settings
Submitter Jason Merrill
Date July 1, 2011, 8:23 p.m.
Message ID <4E0E2CDC.5000201@redhat.com>
Download mbox | patch
Permalink /patch/102968/
State New
Headers show

Comments

Jason Merrill - July 1, 2011, 8:23 p.m.
Replacing assert with error.

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

Patch

commit e42789795f05e88b0b55c5da0670aa827ad046b2
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jul 1 14:06:46 2011 -0400

    	PR c++/48261
    	* pt.c (lookup_template_function): Handle non-function.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 5743159..7236e7e 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -6622,8 +6622,12 @@  lookup_template_function (tree fns, tree arglist)
     return error_mark_node;
 
   gcc_assert (!arglist || TREE_CODE (arglist) == TREE_VEC);
-  gcc_assert (fns && (is_overloaded_fn (fns)
-		      || TREE_CODE (fns) == IDENTIFIER_NODE));
+
+  if (!is_overloaded_fn (fns) && TREE_CODE (fns) != IDENTIFIER_NODE)
+    {
+      error ("%q#D is not a function template", fns);
+      return error_mark_node;
+    }
 
   if (BASELINK_P (fns))
     {
diff --git a/gcc/testsuite/g++.dg/template/template-id-3.C b/gcc/testsuite/g++.dg/template/template-id-3.C
new file mode 100644
index 0000000..e0753ab
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/template-id-3.C
@@ -0,0 +1,22 @@ 
+// PR c++/48261
+
+typedef double (*gaddType)(double,double);
+struct Foo2
+{
+  static gaddType add;
+};
+
+template<typename T>
+struct Something
+{
+  void work()
+  {
+    double x=T::template add<double>(5.0,6.0); // { dg-error "add" }
+  }
+};
+
+int main()
+{
+  Something<Foo2> s2;
+  s2.work();
+}