[cfe-commits] r81062 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/Sema.h lib/Sema/SemaExpr.cpp lib/Sema/SemaTemplateInstantiate.cpp test/SemaTemplate/default-expr-arguments.cpp

Anders Carlsson andersca at mac.com
Fri Sep 4 22:14:19 PDT 2009


Author: andersca
Date: Sat Sep  5 00:14:19 2009
New Revision: 81062

URL: http://llvm.org/viewvc/llvm-project?rev=81062&view=rev
Log:
Use a separate diagnostic for default function argument expressions.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
    cfe/trunk/test/SemaTemplate/default-expr-arguments.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=81062&r1=81061&r2=81062&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Sep  5 00:14:19 2009
@@ -977,6 +977,9 @@
   
 def note_default_arg_instantiation_here : Note<
   "in instantiation of default argument for '%0' required here">;
+def note_default_function_arg_instantiation_here : Note<
+  "in instantiation of default function argument expression "
+  "for '%0' required here">;
 def note_explicit_template_arg_substitution_here : Note<
   "while substituting explicitly-specified template arguments into function "
   "template %f, here">;

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=81062&r1=81061&r2=81062&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sat Sep  5 00:14:19 2009
@@ -2730,6 +2730,11 @@
       /// FIXME: Use a TemplateArgumentList
       DefaultTemplateArgumentInstantiation,
 
+      /// We are instantiating a default argument for a function.
+      /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs
+      /// provides the template arguments as specified.
+      DefaultFunctionArgumentInstantiation,
+
       /// We are substituting explicit template arguments provided for 
       /// a function template. The entity is a FunctionTemplateDecl.
       ExplicitTemplateArgumentSubstitution,
@@ -2778,7 +2783,9 @@
       case DefaultTemplateArgumentInstantiation:
       case ExplicitTemplateArgumentSubstitution:
       case DeducedTemplateArgumentSubstitution:
+      case DefaultFunctionArgumentInstantiation:
         return X.TemplateArgs == Y.TemplateArgs;
+          
       }
 
       return true;
@@ -2852,6 +2859,12 @@
                           unsigned NumTemplateArgs,
                           SourceRange InstantiationRange = SourceRange());
 
+    InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
+                          ParmVarDecl *Param,
+                          const TemplateArgument *TemplateArgs,
+                          unsigned NumTemplateArgs,
+                          SourceRange InstantiationRange = SourceRange());
+
     /// \brief Note that we have finished instantiating this template.
     void Clear();
 

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Sep  5 00:14:19 2009
@@ -2573,12 +2573,9 @@
 
       // Instantiate the expression.
       MultiLevelTemplateArgumentList ArgList = getTemplateInstantiationArgs(FD);
-      
-      // FIXME: We should really make a new InstantiatingTemplate ctor
-      // that has a better message - right now we're just piggy-backing 
-      // off the "default template argument" error message.
-      InstantiatingTemplate Inst(*this, CallLoc, FD->getPrimaryTemplate(),
-                                 ArgList.getInnermost().getFlatArgumentList(),
+
+      InstantiatingTemplate Inst(*this, CallLoc, Param, 
+                                 ArgList.getInnermost().getFlatArgumentList(), 
                                  ArgList.getInnermost().flat_size());
 
       OwningExprResult Result = SubstExpr(UninstExpr, ArgList);

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Sat Sep  5 00:14:19 2009
@@ -164,6 +164,30 @@
   }
 }
 
+Sema::InstantiatingTemplate::InstantiatingTemplate(Sema &SemaRef, 
+                                          SourceLocation PointOfInstantation,
+                                          ParmVarDecl *Param,
+                                          const TemplateArgument *TemplateArgs,
+                                          unsigned NumTemplateArgs,
+                                          SourceRange InstantiationRange)
+  : SemaRef(SemaRef) {
+    
+  Invalid = CheckInstantiationDepth(PointOfInstantation, InstantiationRange);
+
+  if (!Invalid) {
+    ActiveTemplateInstantiation Inst;
+    Inst.Kind
+      = ActiveTemplateInstantiation::DefaultFunctionArgumentInstantiation;
+    Inst.PointOfInstantiation = PointOfInstantation;
+    Inst.Entity = reinterpret_cast<uintptr_t>(Param);
+    Inst.TemplateArgs = TemplateArgs;
+    Inst.NumTemplateArgs = NumTemplateArgs;
+    Inst.InstantiationRange = InstantiationRange;
+    SemaRef.ActiveTemplateInstantiations.push_back(Inst);
+    Invalid = false;
+  }
+}
+
 void Sema::InstantiatingTemplate::Clear() {
   if (!Invalid) {
     SemaRef.ActiveTemplateInstantiations.pop_back();
@@ -266,6 +290,23 @@
       }
       break;
 
+    case ActiveTemplateInstantiation::DefaultFunctionArgumentInstantiation: {
+      ParmVarDecl *Param = cast<ParmVarDecl>((Decl *)Active->Entity);
+      FunctionDecl *FD = cast<FunctionDecl>(Param->getDeclContext());
+      TemplateDecl *Template = FD->getPrimaryTemplate();
+      
+      std::string TemplateArgsStr
+        = TemplateSpecializationType::PrintTemplateArgumentList(
+                                                         Active->TemplateArgs, 
+                                                      Active->NumTemplateArgs,
+                                                      Context.PrintingPolicy);
+      Diags.Report(FullSourceLoc(Active->PointOfInstantiation, SourceMgr),
+                   diag::note_default_function_arg_instantiation_here)
+        << (Template->getNameAsString() + TemplateArgsStr)
+        << Active->InstantiationRange;
+      break;
+    }
+        
     }
   }
 }
@@ -280,6 +321,8 @@
 
     switch(Active->Kind) {
     case ActiveTemplateInstantiation::TemplateInstantiation:
+    case ActiveTemplateInstantiation::DefaultFunctionArgumentInstantiation:
+
       // This is a template instantiation, so there is no SFINAE.
       return false;
         

Modified: cfe/trunk/test/SemaTemplate/default-expr-arguments.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/default-expr-arguments.cpp?rev=81062&r1=81061&r2=81062&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/default-expr-arguments.cpp (original)
+++ cfe/trunk/test/SemaTemplate/default-expr-arguments.cpp Sat Sep  5 00:14:19 2009
@@ -10,28 +10,28 @@
 
 void g() {
   f1(10);
-  f1(S()); // expected-note{{in instantiation of default argument for 'f1<struct S>' required here}}
+  f1(S()); // expected-note{{in instantiation of default function argument expression for 'f1<struct S>' required here}}
   
   f2(10);
   f2(S());
   
   f3(10);
-  f3(S()); // expected-note{{in instantiation of default argument for 'f3<struct S>' required here}}
+  f3(S()); // expected-note{{in instantiation of default function argument expression for 'f3<struct S>' required here}}
 }
 
 template<typename T> struct F {
-	F(T t = 10);
+  F(T t = 10);
 };
 
 struct FD : F<int> { };
 
 void g2() {
-	F<int> f;
+  F<int> f;
   FD fd;
 }
 
 template<typename T> struct G {
-	G(T) {}
+  G(T) {}
 };
 
 void s(G<int> flags = 10) { }





More information about the cfe-commits mailing list