[cfe-commits] r102256 - in /cfe/trunk: lib/Sema/SemaTemplate.cpp test/SemaTemplate/temp_arg_nontype.cpp

Douglas Gregor dgregor at apple.com
Sat Apr 24 11:20:53 PDT 2010


Author: dgregor
Date: Sat Apr 24 13:20:53 2010
New Revision: 102256

URL: http://llvm.org/viewvc/llvm-project?rev=102256&view=rev
Log:
When we take the address of a declaration to bind it to a non-type
template parameter, by sure to mark that declaration as
"referenced". The Boost.Iterator library now passes all tests.

Modified:
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=102256&r1=102255&r2=102256&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Sat Apr 24 13:20:53 2010
@@ -2576,6 +2576,7 @@
 
   // Create the template argument.
   Converted = TemplateArgument(Entity->getCanonicalDecl());
+  S.MarkDeclarationReferenced(Arg->getLocStart(), Entity);
   return false;
 }
 

Modified: cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp?rev=102256&r1=102255&r2=102256&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp (original)
+++ cfe/trunk/test/SemaTemplate/temp_arg_nontype.cpp Sat Apr 24 13:20:53 2010
@@ -176,3 +176,20 @@
     f<512>(arr512); // expected-error{{no matching function for call}}
   }
 }
+
+// Check that we instantiate declarations whose addresses are taken
+// for non-type template arguments.
+namespace EntityReferenced {
+  template<typename T, void (*)(T)> struct X { };
+
+  template<typename T>
+  struct Y {
+    static void f(T x) { 
+      x = 1; // expected-error{{assigning to 'int *' from incompatible type 'int'}}
+    }
+  };
+
+  void g() {
+    typedef X<int*, Y<int*>::f> x; // expected-note{{in instantiation of}}
+  }
+}





More information about the cfe-commits mailing list