[cfe-commits] r71907 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/Expr.cpp lib/Sema/SemaExpr.cpp test/SemaTemplate/instantiate-function-1.cpp

Douglas Gregor dgregor at apple.com
Fri May 15 17:19:10 PDT 2009


On May 15, 2009, at 4:10 PM, Anders Carlsson wrote:

> Author: andersca
> Date: Fri May 15 18:10:19 2009
> New Revision: 71907
>
> URL: http://llvm.org/viewvc/llvm-project?rev=71907&view=rev
> Log:
> Basic support for member exprs where the base expr type is dependent.
>
> Modified:
>    cfe/trunk/include/clang/AST/Expr.h
>    cfe/trunk/lib/AST/Expr.cpp
>    cfe/trunk/lib/Sema/SemaExpr.cpp
>    cfe/trunk/test/SemaTemplate/instantiate-function-1.cpp
>
> Modified: cfe/trunk/include/clang/AST/Expr.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=71907&r1=71906&r2=71907&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/include/clang/AST/Expr.h (original)
> +++ cfe/trunk/include/clang/AST/Expr.h Fri May 15 18:10:19 2009
> @@ -1040,7 +1040,8 @@
> public:
>   MemberExpr(Expr *base, bool isarrow, NamedDecl *memberdecl,  
> SourceLocation l,
>              QualType ty)
> -    : Expr(MemberExprClass, ty),
> +    : Expr(MemberExprClass, ty,
> +           base->isTypeDependent(), base->isValueDependent()),
>       Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow 
> (isarrow) {}
>
>   /// \brief Build an empty member reference expression.
>
> Modified: cfe/trunk/lib/AST/Expr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=71907&r1=71906&r2=71907&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/lib/AST/Expr.cpp (original)
> +++ cfe/trunk/lib/AST/Expr.cpp Fri May 15 18:10:19 2009
> @@ -417,6 +417,11 @@
> /// warning.
> bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange  
> &R1,
>                                   SourceRange &R2) const {
> +  // Don't warn if the expr is type dependent. The type could end up
> +  // instantiating to void.
> +  if (isTypeDependent())
> +    return false;
> +
>   switch (getStmtClass()) {
>   default:
>     Loc = getExprLoc();
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=71907&r1=71906&r2=71907&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri May 15 18:10:19 2009
> @@ -2024,7 +2024,10 @@
>   // Get the type being accessed in BaseType.  If this is an arrow,  
> the BaseExpr
>   // must have pointer type, and the accessed type is the pointee.
>   if (OpKind == tok::arrow) {
> -    if (const PointerType *PT = BaseType->getAsPointerType())
> +    if (BaseType->isDependentType())
> +      return Owned(new (Context) MemberExpr(BaseExpr, true, 0,
> +                                            MemberLoc,  
> Context.DependentTy));
> +    else if (const PointerType *PT = BaseType->getAsPointerType())
>       BaseType = PT->getPointeeType();
>     else if (getLangOptions().CPlusPlus && BaseType->isRecordType())
>       return Owned(BuildOverloadedArrowExpr(S, BaseExpr, OpLoc,
> @@ -2033,6 +2036,17 @@
>       return ExprError(Diag(MemberLoc,
>                              
> diag::err_typecheck_member_reference_arrow)
>         << BaseType << BaseExpr->getSourceRange());
> +  } else {
> +    // We use isTemplateTypeParmType directly here, instead of  
> simply checking
> +    // whether BaseType is dependent, because we want to report an  
> error for
> +    //
> +    // T *t;
> +    // t.foo;
> +    //
> +    //
> +    if (BaseType->isTemplateTypeParmType())
> +      return Owned(new (Context) MemberExpr(BaseExpr, false, 0,
> +                                            MemberLoc,  
> Context.DependentTy));
>   }

I'm assuming that this code is temporary... could you put a FIXME here  
to state that?

   - Doug



More information about the cfe-commits mailing list