r187762 - 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...

Richard Smith richard at metafoo.co.uk
Tue Aug 6 19:17:12 PDT 2013


On Mon, Aug 5, 2013 at 6:03 PM, Larisse Voufo <lvoufo at google.com> wrote:

> Author: lvoufo
> Date: Mon Aug  5 20:03:05 2013
> New Revision: 187762
>
> URL: http://llvm.org/viewvc/llvm-project?rev=187762&view=rev
> Log:
> 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...
>
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=187762&r1=187761&r2=187762&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Aug  5 20:03:05 2013
> @@ -1559,7 +1559,8 @@ Sema::BuildDeclRefExpr(ValueDecl *D, Qua
>  ExprResult
>  Sema::BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK,
>                         const DeclarationNameInfo &NameInfo,
> -                       const CXXScopeSpec *SS, NamedDecl *FoundD) {
> +                       const CXXScopeSpec *SS, NamedDecl *FoundD,
> +                       const TemplateArgumentListInfo *TemplateArgs) {
>    if (getLangOpts().CUDA)
>      if (const FunctionDecl *Caller = dyn_cast<FunctionDecl>(CurContext))
>        if (const FunctionDecl *Callee = dyn_cast<FunctionDecl>(D)) {
> @@ -1578,12 +1579,24 @@ Sema::BuildDeclRefExpr(ValueDecl *D, Qua
>      (CurContext != D->getDeclContext() &&
>       D->getDeclContext()->isFunctionOrMethod());
>
> -  DeclRefExpr *E = DeclRefExpr::Create(Context,
> -                                       SS ?
> SS->getWithLocInContext(Context)
> -                                              : NestedNameSpecifierLoc(),
> -                                       SourceLocation(),
> -                                       D, refersToEnclosingScope,
> -                                       NameInfo, Ty, VK, FoundD);
> +  DeclRefExpr *E;
> +  if (isa<VarTemplateSpecializationDecl>(D)) {
> +    VarTemplateSpecializationDecl *VarSpec =
> +        cast<VarTemplateSpecializationDecl>(D);
> +
> +    E = DeclRefExpr::Create(
> +        Context,
> +        SS ? SS->getWithLocInContext(Context) : NestedNameSpecifierLoc(),
> +        VarSpec->getTemplateKeywordLoc(), D, refersToEnclosingScope,
>

The getTemplateKeywordLoc() here looks wrong: this should be the location
of the 'template' keyword in the expression, not in the declaration. That
is, it should be this 'template':

X::template var<int>
   ^~~~~~~~

not this one:

struct X {
  template<typename T> int var;
  ^~~~~~~~
};


> +        NameInfo.getLoc(), Ty, VK, FoundD, TemplateArgs);
> +  } else {
> +    assert(!TemplateArgs && "No template arguments for non-variable"
> +                            " template specialization referrences");
> +    E = DeclRefExpr::Create(
> +        Context,
> +        SS ? SS->getWithLocInContext(Context) : NestedNameSpecifierLoc(),
> +        SourceLocation(), D, refersToEnclosingScope, NameInfo, Ty, VK,
> FoundD);
> +  }
>
>    MarkDeclRefReferenced(E);
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130806/71294f46/attachment.html>


More information about the cfe-commits mailing list