<div dir="ltr">On 5 August 2013 18:03, Larisse Voufo <span dir="ltr"><<a href="mailto:lvoufo@google.com" target="_blank">lvoufo@google.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Author: lvoufo<br>
Date: Mon Aug  5 20:03:05 2013<br>
New Revision: 187762<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=187762&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=187762&view=rev</a><br>
Log:<br>
Started implementing variable templates. Top level declarations should be fully supported, up to some limitations documented as FIXMEs or TODO. Static data member templates work very partially. Static data member templates of class templates need particular attention...</blockquote>

<div><br></div><div>Nice!!</div><div><br></div><div>[...]</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Modified: cfe/trunk/lib/Parse/ParseDecl.cpp<br>

</blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=187762&r1=187761&r2=187762&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=187762&r1=187761&r2=187762&view=diff</a><br>


==============================================================================<br>
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)<br>
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Aug  5 20:03:05 2013<br>
@@ -1797,24 +1797,69 @@ Decl *Parser::ParseDeclarationAfterDecla<br>
     break;<br>
<br>
   case ParsedTemplateInfo::Template:<br>
-  case ParsedTemplateInfo::ExplicitSpecialization:<br>
+  case ParsedTemplateInfo::ExplicitSpecialization: {<br>
     ThisDecl = Actions.ActOnTemplateDeclarator(getCurScope(),<br>
                                                *TemplateInfo.TemplateParams,<br>
                                                D);<br>
-    break;<br>
<br>
-  case ParsedTemplateInfo::ExplicitInstantiation: {<br>
-    DeclResult ThisRes<br>
-      = Actions.ActOnExplicitInstantiation(getCurScope(),<br>
-                                           TemplateInfo.ExternLoc,<br>
-                                           TemplateInfo.TemplateLoc,<br>
-                                           D);<br>
-    if (ThisRes.isInvalid()) {<br>
+    // If this is a forward declaration of a variable template or variable<br>
+    // template partial specialization with nested name specifier, complain.<br>
+    // FIXME: Move to Sema.<br>
+    CXXScopeSpec &SS = D.getCXXScopeSpec();<br>
+    if (Tok.is(tok::semi) && ThisDecl && SS.isNotEmpty() &&<br>
+        (isa<VarTemplateDecl>(ThisDecl) ||<br>
+         isa<VarTemplatePartialSpecializationDecl>(ThisDecl))) {<br>
+      Diag(SS.getBeginLoc(), diag::err_forward_var_nested_name_specifier)<br>
+          << isa<VarTemplatePartialSpecializationDecl>(ThisDecl)<br>
+          << SS.getRange();<br>
       SkipUntil(tok::semi, true, true);<br>
       return 0;<br>
     }<br>
<br>
-    ThisDecl = ThisRes.get();<br>
+    if (VarTemplateDecl *VT =<br>
+            ThisDecl ? dyn_cast<VarTemplateDecl>(ThisDecl) : 0)<br></blockquote><div><br></div><div>You can use dyn_cast_or_null here.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


+static TemplateSpecializationKind getTemplateSpecializationKind(Decl *D);<br>
+/*<br>
+/// \brief Check the new variable specialization against the parsed input.<br>
+///<br>
+/// FIXME: Model this against function specializations where<br>
+/// a new function declaration is checked against the specialization<br>
+/// as candidate for redefinition... (?)<br>
+static bool CheckVariableTemplateSpecializationType() {<br>
+<br>
+  if (ExpectedType is undeduced &&  ParsedType is not undeduced)<br>
+    ExpectedType = dedudeType();<br>
+<br>
+  if (both types are undeduced)<br>
+    ???;<br>
+<br>
+  bool CheckType = !ExpectedType()-><br>
+<br>
+  if (!Context.hasSameType(DI->getType(), ExpectedDI->getType())) {<br>
+    unsigned ErrStr = IsPartialSpecialization ? 2 : 1;<br>
+    Diag(D.getIdentifierLoc(), diag::err_invalid_var_template_spec_type)<br>
+        << ErrStr << VarTemplate << DI->getType() << ExpectedDI->getType();<br>
+    Diag(VarTemplate->getLocation(), diag::note_template_declared_here)<br>
+        << 2 << VarTemplate->getDeclName();<br>
+    return true;<br>
+  }<br>
+}<br>
+*/<br></blockquote><div><br></div><div>Please don't comment commented out or #if 0'd out code.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=187762&r1=187761&r2=187762&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=187762&r1=187761&r2=187762&view=diff</a><br>


==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Mon Aug  5 20:03:05 2013<br>
@@ -2246,7 +2246,7 @@ FinishTemplateArgumentDeduction(Sema &S,<br>
 }<br>
<br>
 /// \brief Perform template argument deduction to determine whether<br>
-/// the given template arguments match the given class template<br>
+/// the given template arguments match the given variable template<br>
 /// partial specialization per C++ [temp.class.spec.match].<br>
 Sema::TemplateDeductionResult<br>
 Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,<br></blockquote><div><br></div><div>Hm? This is still about classes not variables.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


+/// \brief Perform template argument deduction to determine whether<br>
+/// the given template arguments match the given variable template<br>
+/// partial specialization per C++ [temp.class.spec.match].<br>
+/// TODO: Unify with ClassTemplatePartialSpecializationDecl version.<br>
+Sema::TemplateDeductionResult<br>
+Sema::DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial,<br>
+                              const TemplateArgumentList &TemplateArgs,<br>
+                              TemplateDeductionInfo &Info) {<br>
+  if (Partial->isInvalidDecl())<br>
+    return TDK_Invalid;<br>
+<br>
+  // C++ [temp.class.spec.match]p2:<br>
+  //   A partial specialization matches a given actual template<br>
+  //   argument list if the template arguments of the partial<br>
+  //   specialization can be deduced from the actual template argument<br>
+  //   list (14.8.2).<br>
+<br>
+  // Unevaluated SFINAE context.<br>
+  EnterExpressionEvaluationContext Unevaluated(*this, Sema::Unevaluated);<br>
+  SFINAETrap Trap(*this);<br>
+<br>
+  SmallVector<DeducedTemplateArgument, 4> Deduced;<br>
+  Deduced.resize(Partial->getTemplateParameters()->size());<br>
+  if (TemplateDeductionResult Result = ::DeduceTemplateArguments(<br>
+          *this, Partial->getTemplateParameters(), Partial->getTemplateArgs(),<br>
+          TemplateArgs, Info, Deduced))<br>
+    return Result;<br></blockquote><div><br></div><div>What's up with the leading :: on the function call?</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


+<br>
+  SmallVector<TemplateArgument, 4> DeducedArgs(Deduced.begin(), Deduced.end());<br>
+  InstantiatingTemplate Inst(*this, Partial->getLocation(), Partial,<br>
+                             DeducedArgs, Info);<br>
+  if (Inst)<br>
+    return TDK_InstantiationDepth;<br>
+<br>
+  if (Trap.hasErrorOccurred())<br>
+    return Sema::TDK_SubstitutionFailure;<br>
+<br>
+  return ::FinishTemplateArgumentDeduction(*this, Partial, TemplateArgs,<br>
+                                           Deduced, Info);<br></blockquote><div><br></div><div>And again here?</div><div><br></div><div>Nick</div><div> </div></div></div></div>