[cfe-commits] r84363 - in /cfe/trunk: lib/Sema/SemaOverload.cpp test/CodeGenCXX/address-of-fntemplate.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Sat Oct 17 14:12:12 PDT 2009


Author: cornedbee
Date: Sat Oct 17 16:12:09 2009
New Revision: 84363

URL: http://llvm.org/viewvc/llvm-project?rev=84363&view=rev
Log:
When resolving the address of an overloaded function or function template, mark the result as referenced.

The most important effect of this is that function templates only referenced by address expressions now get instantiated. This, in turn, means that Hello World compiles with the Apache stdcxx library even when using endl.

Modified:
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/test/CodeGenCXX/address-of-fntemplate.cpp

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=84363&r1=84362&r2=84363&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Sat Oct 17 16:12:09 2009
@@ -4334,8 +4334,11 @@
   // If there were 0 or 1 matches, we're done.
   if (Matches.empty())
     return 0;
-  else if (Matches.size() == 1)
-    return *Matches.begin();
+  else if (Matches.size() == 1) {
+    FunctionDecl *Result = *Matches.begin();
+    MarkDeclarationReferenced(From->getLocStart(), Result);
+    return Result;
+  }
 
   // C++ [over.over]p4:
   //   If more than one function is selected, [...]
@@ -4351,14 +4354,17 @@
     // two-pass algorithm (similar to the one used to identify the
     // best viable function in an overload set) that identifies the
     // best function template (if it exists).
-    llvm::SmallVector<FunctionDecl *, 8> TemplateMatches(Matches.begin(), 
+    llvm::SmallVector<FunctionDecl *, 8> TemplateMatches(Matches.begin(),
                                                          Matches.end());
-    return getMostSpecialized(TemplateMatches.data(), TemplateMatches.size(), 
-                              TPOC_Other, From->getLocStart(),
-                              PDiag(),
-                              PDiag(diag::err_addr_ovl_ambiguous)
-                              << TemplateMatches[0]->getDeclName(), 
-                              PDiag(diag::err_ovl_template_candidate));
+    FunctionDecl *Result =
+        getMostSpecialized(TemplateMatches.data(), TemplateMatches.size(),
+                           TPOC_Other, From->getLocStart(),
+                           PDiag(),
+                           PDiag(diag::err_addr_ovl_ambiguous)
+                               << TemplateMatches[0]->getDeclName(),
+                           PDiag(diag::err_ovl_template_candidate));
+    MarkDeclarationReferenced(From->getLocStart(), Result);
+    return Result;
   }
 
   //   [...] any function template specializations in the set are
@@ -4370,8 +4376,11 @@
   
   // [...] After such eliminations, if any, there shall remain exactly one
   // selected function.
-  if (RemainingMatches.size() == 1)
-    return RemainingMatches.front();
+  if (RemainingMatches.size() == 1) {
+    FunctionDecl *Result = RemainingMatches.front();
+    MarkDeclarationReferenced(From->getLocStart(), Result);
+    return Result;
+  }
 
   // FIXME: We should probably return the same thing that BestViableFunction
   // returns (even if we issue the diagnostics here).

Modified: cfe/trunk/test/CodeGenCXX/address-of-fntemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/address-of-fntemplate.cpp?rev=84363&r1=84362&r2=84363&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/address-of-fntemplate.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/address-of-fntemplate.cpp Sat Oct 17 16:12:09 2009
@@ -2,8 +2,7 @@
 template <typename T> void f(T) {}
 
 void test() {
-  // FIXME: This emits only a declaration instead of a definition
   // CHECK: @_Z1fIiEvT_
   void (*p)(int) = &f;
 }
-// CHECK-disabled: define linkonce_odr void @_Z1fIiEvT_
+// CHECK: define linkonce_odr void @_Z1fIiEvT_





More information about the cfe-commits mailing list