[cfe-dev] Explicit this expression in class template is dependent?

Reid Kleckner rnk at google.com
Fri Aug 22 13:21:26 PDT 2014


I think the only way this could be dependent is if you have dependent
bases, but there may be awkward cases I haven't thought about.

Consider this code in SemaExprMember.cpp:
ExprResult
Sema::BuildMemberReferenceExpr(Expr *Base, QualType BaseType,
                               SourceLocation OpLoc, bool IsArrow,
                               CXXScopeSpec &SS,
                               SourceLocation TemplateKWLoc,
                               NamedDecl *FirstQualifierInScope,
                               const DeclarationNameInfo &NameInfo,
                               const TemplateArgumentListInfo *TemplateArgs,
                               ActOnMemberAccessExtraArgs *ExtraArgs) {
  if (BaseType->isDependentType() ||
      (SS.isSet() && isDependentScopeSpecifier(SS)))
    return ActOnDependentMemberExpr(Base, BaseType,
                                    IsArrow, OpLoc,
                                    SS, TemplateKWLoc,
FirstQualifierInScope,
                                    NameInfo, TemplateArgs);

Perhaps it could look at the BaseType to see if it is a record decl that
does not have any dependent bases, and in that case form a regular
MemberExpr.

In the implicit case, i is unqualified and ADL doesn't fire, so it can't be
dependent.


On Fri, Aug 22, 2014 at 12:56 PM, Jason Haslam <jason.haslam at gmail.com>
wrote:

> Hi all,
>
> I find that explicit this expressions in class templates create a
> CXXDependentScopeMemberExpr in the AST while the equivalent implicit this
> is a MemberExpr. For example code like this:
>
> template <typename T> struct A {
>   int i;
>   int getImplicit() { return i; } // MemberExpr
>   int getExplicit() { return this->i; } // CXXDependentScopeMemberExpr
> };
>
> Why is explicit dependent? Is it technical (per the language standard) or
> an implementation detail? I’d like both expressions to resolve to the
> member for static analysis/refactoring/etc.
>
> Jason
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140822/479355ab/attachment.html>


More information about the cfe-dev mailing list