diff options
author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2009-07-29 13:50:23 +0000 |
---|---|---|
committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2009-07-29 13:50:23 +0000 |
commit | 955a067bddaae567ee48261da14c7438d613a84e (patch) | |
tree | d1301cc49c8aa81ccc08304d7dbe359b93c9c842 /clang/lib/Sema | |
parent | 573720e18585e852523adb2a06cbf105b8e4320d (diff) | |
download | bcm5719-llvm-955a067bddaae567ee48261da14c7438d613a84e.tar.gz bcm5719-llvm-955a067bddaae567ee48261da14c7438d613a84e.zip |
Make functional-style casts emit correct messages, and fix a crash-on-invalid.
llvm-svn: 77451
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/Sema.h | 8 | ||||
-rw-r--r-- | clang/lib/Sema/SemaCXXCast.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 5 | ||||
-rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 2 |
4 files changed, 12 insertions, 9 deletions
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h index 6737175fcf3..79ea3e13030 100644 --- a/clang/lib/Sema/Sema.h +++ b/clang/lib/Sema/Sema.h @@ -3171,8 +3171,9 @@ public: bool ForceRValue = false); /// CheckCastTypes - Check type constraints for casting between types under - /// C semantics. - bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr); + /// C semantics, or forward to CXXCheckCStyleCast in C++. + bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr, + bool FunctionalStyle = false); // CheckVectorCast - check type constraints for vectors. // Since vectors are an extension, there are no C standard reference for this. @@ -3189,7 +3190,8 @@ public: /// CXXCheckCStyleCast - Check constraints of a C-style or function-style /// cast under C++ semantics. - bool CXXCheckCStyleCast(SourceRange R, QualType CastTy, Expr *&CastExpr); + bool CXXCheckCStyleCast(SourceRange R, QualType CastTy, Expr *&CastExpr, + bool FunctionalStyle); /// CheckMessageArgumentTypes - Check types in an Obj-C message send. /// \param Method - May be null. diff --git a/clang/lib/Sema/SemaCXXCast.cpp b/clang/lib/Sema/SemaCXXCast.cpp index f83a9f291a6..99bf84565d1 100644 --- a/clang/lib/Sema/SemaCXXCast.cpp +++ b/clang/lib/Sema/SemaCXXCast.cpp @@ -999,7 +999,8 @@ static TryCastResult TryReinterpretCast(Sema &Self, Expr *SrcExpr, } -bool Sema::CXXCheckCStyleCast(SourceRange R, QualType CastTy, Expr *&CastExpr) +bool Sema::CXXCheckCStyleCast(SourceRange R, QualType CastTy, Expr *&CastExpr, + bool FunctionalStyle) { // This test is outside everything else because it's the only case where // a non-lvalue-reference target type does not lead to decay. @@ -1036,9 +1037,8 @@ bool Sema::CXXCheckCStyleCast(SourceRange R, QualType CastTy, Expr *&CastExpr) } } - // FIXME: Differentiate functional-style and C-style cast. if (tcr != TC_Success && msg != 0) - Diag(R.getBegin(), msg) << CT_CStyle + Diag(R.getBegin(), msg) << (FunctionalStyle ? CT_Functional : CT_CStyle) << CastExpr->getType() << CastTy << R; return tcr != TC_Success; diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 473ecef8d0b..ba9d51dfb56 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -2918,9 +2918,10 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, MultiExprArg initlist, } /// CheckCastTypes - Check type constraints for casting between types. -bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *&castExpr) { +bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *&castExpr, + bool FunctionalStyle) { if (getLangOptions().CPlusPlus) - return CXXCheckCStyleCast(TyR, castType, castExpr); + return CXXCheckCStyleCast(TyR, castType, castExpr, FunctionalStyle); UsualUnaryConversions(castExpr); diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 144dc5095f8..a05c76240fa 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -203,7 +203,7 @@ Sema::ActOnCXXTypeConstructExpr(SourceRange TypeRange, TypeTy *TypeRep, // corresponding cast expression. // if (NumExprs == 1) { - if (CheckCastTypes(TypeRange, Ty, Exprs[0])) + if (CheckCastTypes(TypeRange, Ty, Exprs[0], /*functional-style*/true)) return ExprError(); exprs.release(); return Owned(new (Context) CXXFunctionalCastExpr(Ty.getNonReferenceType(), |