Patchwork C++ PATCH for c++/48883, c++/49609 (not instantiating function selected with a template-id)

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

Comments

Jason Merrill - July 1, 2011, 8:21 p.m.
Since DR 115, people have been able to designate a single function 
specialization with a template-id.  When it's then used in a call it 
gets marked used, but uses in other situations weren't getting marked, 
leading to undefined symbol errors.

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

Patch

commit 7b1b0825bcc1531d35b4c25a38392105da7c1c95
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jul 1 12:42:09 2011 -0400

    	PR c++/48883
    	PR c++/49609
    	* pt.c (resolve_nondeduced_context): Call mark_used.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 4903044..947e19e 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -14679,6 +14679,7 @@  resolve_nondeduced_context (tree orig_expr)
 	}
       if (good == 1)
 	{
+	  mark_used (goodfn);
 	  expr = goodfn;
 	  if (baselink)
 	    expr = build_baselink (BASELINK_BINFO (baselink),
diff --git a/gcc/testsuite/g++.dg/template/explicit-args4.C b/gcc/testsuite/g++.dg/template/explicit-args4.C
new file mode 100644
index 0000000..c64a085
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/explicit-args4.C
@@ -0,0 +1,14 @@ 
+// PR c++/48883
+// { dg-do link }
+
+template<typename T>
+T myMax(T a, T b) {
+   if(a < b) return a;
+   return b;
+}
+
+int main() {
+   bool even = true;
+   int (*fp)(int, int);
+   fp = even ? myMax<int> : myMax<int>;   /* yields link error */
+}