diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2017-06-10 17:49:23 +0000 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2017-06-10 17:49:23 +0000 |
commit | 5806d9f205f88c77ea071c0af8444830896f038b (patch) | |
tree | ca0f1fb44431ad4fbaed9d1c1416c54fec790087 /clang/lib/Sema/SemaCast.cpp | |
parent | b0120740c42bba99a83e33930f3c04db6a2af2c4 (diff) | |
download | bcm5719-llvm-5806d9f205f88c77ea071c0af8444830896f038b.tar.gz bcm5719-llvm-5806d9f205f88c77ea071c0af8444830896f038b.zip |
Revert "[clang] Implement -Wcast-qual for C++"
Breaks -Werror builders.
llvm-svn: 305148
Diffstat (limited to 'clang/lib/Sema/SemaCast.cpp')
-rw-r--r-- | clang/lib/Sema/SemaCast.cpp | 94 |
1 files changed, 24 insertions, 70 deletions
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp index ba2049d8a60..7d534263f46 100644 --- a/clang/lib/Sema/SemaCast.cpp +++ b/clang/lib/Sema/SemaCast.cpp @@ -143,9 +143,6 @@ namespace { }; } -static void DiagnoseCastQual(Sema &Self, const ExprResult &SrcExpr, - QualType DestType); - // The Try functions attempt a specific way of casting. If they succeed, they // return TC_Success. If their way of casting is not appropriate for the given // arguments, they return TC_NotApplicable and *may* set diag to a diagnostic @@ -430,10 +427,6 @@ static void diagnoseBadCast(Sema &S, unsigned msg, CastType castType, /// the same kind of pointer (plain or to-member). Unlike the Sema function, /// this one doesn't care if the two pointers-to-member don't point into the /// same class. This is because CastsAwayConstness doesn't care. -/// And additionally, it handles C++ references. If both the types are -/// references, then their pointee types are returned, -/// else if only one of them is reference, it's pointee type is returned, -/// and the other type is returned as-is. static bool UnwrapDissimilarPointerTypes(QualType& T1, QualType& T2) { const PointerType *T1PtrType = T1->getAs<PointerType>(), *T2PtrType = T2->getAs<PointerType>(); @@ -482,26 +475,6 @@ static bool UnwrapDissimilarPointerTypes(QualType& T1, QualType& T2) { return true; } - const LValueReferenceType *T1RefType = T1->getAs<LValueReferenceType>(), - *T2RefType = T2->getAs<LValueReferenceType>(); - if (T1RefType && T2RefType) { - T1 = T1RefType->getPointeeType(); - T2 = T2RefType->getPointeeType(); - return true; - } - - if (T1RefType) { - T1 = T1RefType->getPointeeType(); - // T2 = T2; - return true; - } - - if (T2RefType) { - // T1 = T1; - T2 = T2RefType->getPointeeType(); - return true; - } - return false; } @@ -530,13 +503,11 @@ CastsAwayConstness(Sema &Self, QualType SrcType, QualType DestType, // the rules are non-trivial. So first we construct Tcv *...cv* as described // in C++ 5.2.11p8. assert((SrcType->isAnyPointerType() || SrcType->isMemberPointerType() || - SrcType->isBlockPointerType() || - DestType->isLValueReferenceType()) && + SrcType->isBlockPointerType()) && "Source type is not pointer or pointer to member."); assert((DestType->isAnyPointerType() || DestType->isMemberPointerType() || - DestType->isBlockPointerType() || - DestType->isLValueReferenceType()) && - "Destination type is not pointer or pointer to member, or reference."); + DestType->isBlockPointerType()) && + "Destination type is not pointer or pointer to member."); QualType UnwrappedSrcType = Self.Context.getCanonicalType(SrcType), UnwrappedDestType = Self.Context.getCanonicalType(DestType); @@ -2206,8 +2177,6 @@ static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr, void CastOperation::CheckCXXCStyleCast(bool FunctionalStyle, bool ListInitialization) { - assert(Self.getLangOpts().CPlusPlus); - // Handle placeholders. if (isPlaceholder()) { // C-style casts can resolve __unknown_any types. @@ -2611,42 +2580,30 @@ void CastOperation::CheckCStyleCast() { if (Kind == CK_BitCast) checkCastAlign(); -} - -/// DiagnoseCastQual - Warn whenever casts discards a qualifiers, be it either -/// const, volatile or both. -static void DiagnoseCastQual(Sema &Self, const ExprResult &SrcExpr, - QualType DestType) { - if (SrcExpr.isInvalid()) - return; - - QualType SrcType = SrcExpr.get()->getType(); - if (!((SrcType->isAnyPointerType() && DestType->isAnyPointerType()) || - DestType->isLValueReferenceType())) - return; + // -Wcast-qual QualType TheOffendingSrcType, TheOffendingDestType; Qualifiers CastAwayQualifiers; - if (!CastsAwayConstness(Self, SrcType, DestType, true, false, - &TheOffendingSrcType, &TheOffendingDestType, - &CastAwayQualifiers)) - return; - - int qualifiers = -1; - if (CastAwayQualifiers.hasConst() && CastAwayQualifiers.hasVolatile()) { - qualifiers = 0; - } else if (CastAwayQualifiers.hasConst()) { - qualifiers = 1; - } else if (CastAwayQualifiers.hasVolatile()) { - qualifiers = 2; - } - // This is a variant of int **x; const int **y = (const int **)x; - if (qualifiers == -1) - Self.Diag(SrcExpr.get()->getLocStart(), diag::warn_cast_qual2) - << SrcType << DestType; - else - Self.Diag(SrcExpr.get()->getLocStart(), diag::warn_cast_qual) - << TheOffendingSrcType << TheOffendingDestType << qualifiers; + if (SrcType->isAnyPointerType() && DestType->isAnyPointerType() && + CastsAwayConstness(Self, SrcType, DestType, true, false, + &TheOffendingSrcType, &TheOffendingDestType, + &CastAwayQualifiers)) { + int qualifiers = -1; + if (CastAwayQualifiers.hasConst() && CastAwayQualifiers.hasVolatile()) { + qualifiers = 0; + } else if (CastAwayQualifiers.hasConst()) { + qualifiers = 1; + } else if (CastAwayQualifiers.hasVolatile()) { + qualifiers = 2; + } + // This is a variant of int **x; const int **y = (const int **)x; + if (qualifiers == -1) + Self.Diag(SrcExpr.get()->getLocStart(), diag::warn_cast_qual2) << + SrcType << DestType; + else + Self.Diag(SrcExpr.get()->getLocStart(), diag::warn_cast_qual) << + TheOffendingSrcType << TheOffendingDestType << qualifiers; + } } ExprResult Sema::BuildCStyleCastExpr(SourceLocation LPLoc, @@ -2667,9 +2624,6 @@ ExprResult Sema::BuildCStyleCastExpr(SourceLocation LPLoc, if (Op.SrcExpr.isInvalid()) return ExprError(); - // -Wcast-qual - DiagnoseCastQual(Op.Self, Op.SrcExpr, Op.DestType); - return Op.complete(CStyleCastExpr::Create(Context, Op.ResultType, Op.ValueKind, Op.Kind, Op.SrcExpr.get(), &Op.BasePath, CastTypeInfo, LPLoc, RPLoc)); |