From eea8ba097c4a86632b88291bea51eb710f8ae4fb Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 16 Dec 2019 18:26:19 -0800 Subject: Check whether the destination is a complete type in a static_cast (or C-style cast) to an enumeration type. We previously forgot to check this, and happened to get away with it (with bad diagnostics) only because we misclassified incomplete enumeration types as not being unscoped enumeration types. This also fixes the misclassification. --- clang/lib/Sema/SemaCast.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'clang/lib/Sema/SemaCast.cpp') diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp index 741cf638760..d0b9fe12289 100644 --- a/clang/lib/Sema/SemaCast.cpp +++ b/clang/lib/Sema/SemaCast.cpp @@ -740,7 +740,7 @@ void CastOperation::CheckDynamicCast() { assert(DestPointer && "Reference to void is not possible"); } else if (DestRecord) { if (Self.RequireCompleteType(OpRange.getBegin(), DestPointee, - diag::err_bad_dynamic_cast_incomplete, + diag::err_bad_cast_incomplete, DestRange)) { SrcExpr = ExprError(); return; @@ -785,7 +785,7 @@ void CastOperation::CheckDynamicCast() { const RecordType *SrcRecord = SrcPointee->getAs(); if (SrcRecord) { if (Self.RequireCompleteType(OpRange.getBegin(), SrcPointee, - diag::err_bad_dynamic_cast_incomplete, + diag::err_bad_cast_incomplete, SrcExpr.get())) { SrcExpr = ExprError(); return; @@ -1182,6 +1182,11 @@ static TryCastResult TryStaticCast(Sema &Self, ExprResult &SrcExpr, // The same goes for reverse floating point promotion/conversion and // floating-integral conversions. Again, only floating->enum is relevant. if (DestType->isEnumeralType()) { + if (Self.RequireCompleteType(OpRange.getBegin(), DestType, + diag::err_bad_cast_incomplete)) { + SrcExpr = ExprError(); + return TC_Failed; + } if (SrcType->isIntegralOrEnumerationType()) { Kind = CK_IntegralCast; return TC_Success; @@ -1651,7 +1656,7 @@ TryStaticImplicitCast(Sema &Self, ExprResult &SrcExpr, QualType DestType, CastKind &Kind, bool ListInitialization) { if (DestType->isRecordType()) { if (Self.RequireCompleteType(OpRange.getBegin(), DestType, - diag::err_bad_dynamic_cast_incomplete) || + diag::err_bad_cast_incomplete) || Self.RequireNonAbstractType(OpRange.getBegin(), DestType, diag::err_allocation_of_abstract_type)) { msg = 0; -- cgit v1.2.3