[cfe-commits] r61165 - in /cfe/trunk: include/clang/AST/Expr.h lib/Sema/SemaExpr.cpp lib/Sema/SemaNamedCast.cpp test/SemaCXX/type-dependent-exprs.cpp

Douglas Gregor dgregor at apple.com
Wed Dec 17 14:52:21 PST 2008


Author: dgregor
Date: Wed Dec 17 16:52:20 2008
New Revision: 61165

URL: http://llvm.org/viewvc/llvm-project?rev=61165&view=rev
Log:
Delay semantic analysis of the C++ names casts when the subexpression is type-dependent or the destination type is dependent.

Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaNamedCast.cpp
    cfe/trunk/test/SemaCXX/type-dependent-exprs.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=61165&r1=61164&r2=61165&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Dec 17 16:52:20 2008
@@ -555,7 +555,10 @@
 public:  
 
   UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l)
-    : Expr(UnaryOperatorClass, type), Val(input), Opc(opc), Loc(l) {}
+    : Expr(UnaryOperatorClass, type,
+           input->isTypeDependent() && opc != OffsetOf,
+           input->isValueDependent()), 
+      Val(input), Opc(opc), Loc(l) {}
 
   Opcode getOpcode() const { return Opc; }
   Expr *getSubExpr() const { return cast<Expr>(Val); }

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Dec 17 16:52:20 2008
@@ -2876,6 +2876,9 @@
 /// In C++, the operand might be an overloaded function name, in which case 
 /// we allow the '&' but retain the overloaded-function type.
 QualType Sema::CheckAddressOfOperand(Expr *op, SourceLocation OpLoc) {
+  if (op->isTypeDependent())
+    return Context.DependentTy;
+
   if (getLangOptions().C99) {
     // Implement C99-only parts of addressof rules.
     if (UnaryOperator* uOp = dyn_cast<UnaryOperator>(op)) {

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaNamedCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaNamedCast.cpp Wed Dec 17 16:52:20 2008
@@ -65,26 +65,34 @@
   SourceRange OpRange(OpLoc, RParenLoc);
   SourceRange DestRange(LAngleBracketLoc, RAngleBracketLoc);
 
+  // If the type is dependent, we won't do the semantic analysis now.
+  // FIXME: should we check this in a more fine-grained manner?
+  bool TypeDependent = DestType->isDependentType() || Ex->isTypeDependent();
+
   switch (Kind) {
   default: assert(0 && "Unknown C++ cast!");
 
   case tok::kw_const_cast:
-    CheckConstCast(*this, Ex, DestType, OpRange, DestRange);
+    if (!TypeDependent)
+      CheckConstCast(*this, Ex, DestType, OpRange, DestRange);
     return new CXXConstCastExpr(DestType.getNonReferenceType(), Ex, 
                                 DestType, OpLoc);
 
   case tok::kw_dynamic_cast:
-    CheckDynamicCast(*this, Ex, DestType, OpRange, DestRange);
+    if (!TypeDependent)
+      CheckDynamicCast(*this, Ex, DestType, OpRange, DestRange);
     return new CXXDynamicCastExpr(DestType.getNonReferenceType(), Ex, 
                                   DestType, OpLoc);
 
   case tok::kw_reinterpret_cast:
-    CheckReinterpretCast(*this, Ex, DestType, OpRange, DestRange);
+    if (!TypeDependent)
+      CheckReinterpretCast(*this, Ex, DestType, OpRange, DestRange);
     return new CXXReinterpretCastExpr(DestType.getNonReferenceType(), Ex, 
                                       DestType, OpLoc);
 
   case tok::kw_static_cast:
-    CheckStaticCast(*this, Ex, DestType, OpRange);
+    if (!TypeDependent)
+      CheckStaticCast(*this, Ex, DestType, OpRange);
     return new CXXStaticCastExpr(DestType.getNonReferenceType(), Ex, 
                                  DestType, OpLoc);
   }

Modified: cfe/trunk/test/SemaCXX/type-dependent-exprs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/type-dependent-exprs.cpp?rev=61165&r1=61164&r2=61165&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/type-dependent-exprs.cpp (original)
+++ cfe/trunk/test/SemaCXX/type-dependent-exprs.cpp Wed Dec 17 16:52:20 2008
@@ -1,4 +1,8 @@
 // RUN: clang -fsyntax-only -verify %s
+class X { 
+public:
+  virtual int f();
+};
 
 void g(int);
 
@@ -8,6 +12,10 @@
   (void)T(0);
   (void)(x += 0);
   (void)(x? x : x);
+  (void)static_cast<int>(x);
+  (void)reinterpret_cast<int>(x);
+  (void)dynamic_cast<X*>(&x);
+  (void)const_cast<int>(x);
   return g(x);
   h(x); // h is a dependent name
   g(1, 1); // expected-error{{too many arguments to function call}}





More information about the cfe-commits mailing list