start converting Sema over to using its canonical Diag method.

llvm-svn: 59561
This commit is contained in:
Chris Lattner 2008-11-18 22:52:51 +00:00
parent 83f45b55f8
commit 377d1f8eae
9 changed files with 137 additions and 164 deletions

View File

@ -200,15 +200,6 @@ bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID) << Msg1 << Msg2 << R;
return true;
}
bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
const std::string &Msg2, const std::string &Msg3,
const SourceRange &R1) {
PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID)
<< Msg1 << Msg2 << Msg3 << R1;
return true;
}
bool Sema::Diag(SourceLocation Loc, unsigned DiagID,
const SourceRange& R1, const SourceRange& R2) {
PP.getDiagnostics().Report(PP.getFullLoc(Loc), DiagID) << R1 << R2;
@ -221,14 +212,6 @@ bool Sema::Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
return true;
}
bool Sema::Diag(SourceLocation Range, unsigned DiagID, const std::string &Msg1,
const std::string &Msg2, const SourceRange& R1,
const SourceRange& R2) {
PP.getDiagnostics().Report(PP.getFullLoc(Range),DiagID)
<< Msg1 << Msg2 << R1 << R2;
return true;
}
const LangOptions &Sema::getLangOptions() const {
return PP.getLangOptions();
}

View File

@ -253,12 +253,6 @@ public:
const SourceRange& R1, const SourceRange& R2);
bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
const std::string &Msg2, const SourceRange& R1);
bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
const std::string &Msg2, const std::string &Msg3,
const SourceRange& R1);
bool Diag(SourceLocation Loc, unsigned DiagID,
const std::string &Msg1, const std::string &Msg2,
const SourceRange& R1, const SourceRange& R2);
virtual void DeleteExpr(ExprTy *E);
virtual void DeleteStmt(StmtTy *S);

View File

@ -714,14 +714,12 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType,
// destination type.
// FIXME: We're pretending to do copy elision here; return to
// this when we have ASTs for such things.
if (PerformImplicitConversion(Init, DeclType))
return Diag(InitLoc,
diag::err_typecheck_convert_incompatible,
DeclType.getAsString(), InitEntity,
"initializing",
Init->getSourceRange());
else
if (!PerformImplicitConversion(Init, DeclType))
return false;
return Diag(InitLoc, diag::err_typecheck_convert_incompatible)
<< DeclType.getAsString() << InitEntity << "initializing"
<< Init->getSourceRange();
}
// C99 6.7.8p16.

View File

@ -1735,10 +1735,10 @@ Sema::CheckReferenceInit(Expr *&Init, QualType &DeclType,
if (T1.getCVRQualifiers() != QualType::Const) {
if (!ICS)
Diag(Init->getSourceRange().getBegin(),
diag::err_not_reference_to_const_init,
T1.getAsString(),
InitLvalue != Expr::LV_Valid? "temporary" : "value",
T2.getAsString(), Init->getSourceRange());
diag::err_not_reference_to_const_init)
<< T1.getAsString()
<< (InitLvalue != Expr::LV_Valid? "temporary" : "value")
<< T2.getAsString() << Init->getSourceRange();
return true;
}
@ -1799,10 +1799,10 @@ Sema::CheckReferenceInit(Expr *&Init, QualType &DeclType,
// initialization fails.
if (!ICS)
Diag(Init->getSourceRange().getBegin(),
diag::err_reference_init_drops_quals,
T1.getAsString(),
InitLvalue != Expr::LV_Valid? "temporary" : "value",
T2.getAsString(), Init->getSourceRange());
diag::err_reference_init_drops_quals)
<< T1.getAsString()
<< (InitLvalue != Expr::LV_Valid? "temporary" : "value")
<< T2.getAsString() << Init->getSourceRange();
return true;
}

View File

@ -256,34 +256,28 @@ Sema::DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
Property->getName(), inheritedName);
if ((CAttr & ObjCPropertyDecl::OBJC_PR_copy)
!= (SAttr & ObjCPropertyDecl::OBJC_PR_copy))
Diag(Property->getLocation(), diag::warn_property_attribute,
Property->getName(), "copy", inheritedName,
SourceRange());
Diag(Property->getLocation(), diag::warn_property_attribute)
<< Property->getName() << "copy" << inheritedName;
else if ((CAttr & ObjCPropertyDecl::OBJC_PR_retain)
!= (SAttr & ObjCPropertyDecl::OBJC_PR_retain))
Diag(Property->getLocation(), diag::warn_property_attribute,
Property->getName(), "retain", inheritedName,
SourceRange());
Diag(Property->getLocation(), diag::warn_property_attribute)
<< Property->getName() << "retain" << inheritedName;
if ((CAttr & ObjCPropertyDecl::OBJC_PR_nonatomic)
!= (SAttr & ObjCPropertyDecl::OBJC_PR_nonatomic))
Diag(Property->getLocation(), diag::warn_property_attribute,
Property->getName(), "atomic", inheritedName,
SourceRange());
Diag(Property->getLocation(), diag::warn_property_attribute)
<< Property->getName() << "atomic" << inheritedName;
if (Property->getSetterName() != SuperProperty->getSetterName())
Diag(Property->getLocation(), diag::warn_property_attribute,
Property->getName(), "setter", inheritedName,
SourceRange());
Diag(Property->getLocation(), diag::warn_property_attribute)
<< Property->getName() << "setter" << inheritedName;
if (Property->getGetterName() != SuperProperty->getGetterName())
Diag(Property->getLocation(), diag::warn_property_attribute,
Property->getName(), "getter", inheritedName,
SourceRange());
Diag(Property->getLocation(), diag::warn_property_attribute)
<< Property->getName() << "getter" << inheritedName;
if (Context.getCanonicalType(Property->getType()) !=
Context.getCanonicalType(SuperProperty->getType()))
Diag(Property->getLocation(), diag::warn_property_type,
Property->getType().getAsString(),
inheritedName);
Diag(Property->getLocation(), diag::warn_property_type)
<< Property->getType().getAsString() << inheritedName;
}

View File

@ -1521,9 +1521,9 @@ inline QualType Sema::CheckConditionalOperands( // C99 6.5.15
}
} else if (!Context.typesAreCompatible(lhptee.getUnqualifiedType(),
rhptee.getUnqualifiedType())) {
Diag(questionLoc, diag::warn_typecheck_cond_incompatible_pointers,
lexT.getAsString(), rexT.getAsString(),
lex->getSourceRange(), rex->getSourceRange());
Diag(questionLoc, diag::warn_typecheck_cond_incompatible_pointers)
<< lexT.getAsString() << rexT.getAsString()
<< lex->getSourceRange() << rex->getSourceRange();
// In this situation, we assume void* type. No especially good
// reason, but this is what gcc does, and we do have to pick
// to get a consistent AST.
@ -1575,9 +1575,9 @@ inline QualType Sema::CheckConditionalOperands( // C99 6.5.15
return lexT;
// Otherwise, the operands are not compatible.
Diag(questionLoc, diag::err_typecheck_cond_incompatible_operands,
lexT.getAsString(), rexT.getAsString(),
lex->getSourceRange(), rex->getSourceRange());
Diag(questionLoc, diag::err_typecheck_cond_incompatible_operands)
<< lexT.getAsString() << rexT.getAsString()
<< lex->getSourceRange() << rex->getSourceRange();
return QualType();
}
@ -1892,9 +1892,9 @@ Sema::CheckCompoundAssignmentConstraints(QualType lhsType, QualType rhsType) {
}
QualType Sema::InvalidOperands(SourceLocation Loc, Expr *&lex, Expr *&rex) {
Diag(Loc, diag::err_typecheck_invalid_operands,
lex->getType().getAsString(), rex->getType().getAsString(),
lex->getSourceRange(), rex->getSourceRange());
Diag(Loc, diag::err_typecheck_invalid_operands)
<< lex->getType().getAsString() << rex->getType().getAsString()
<< lex->getSourceRange() << rex->getSourceRange();
return QualType();
}
@ -1947,9 +1947,9 @@ inline QualType Sema::CheckVectorOperands(SourceLocation Loc, Expr *&lex,
}
// You cannot convert between vector values of different size.
Diag(Loc, diag::err_typecheck_vector_not_convertable,
lex->getType().getAsString(), rex->getType().getAsString(),
lex->getSourceRange(), rex->getSourceRange());
Diag(Loc, diag::err_typecheck_vector_not_convertable)
<< lex->getType().getAsString() << rex->getType().getAsString()
<< lex->getSourceRange() << rex->getSourceRange();
return QualType();
}
@ -2074,9 +2074,9 @@ QualType Sema::CheckSubtractionOperands(Expr *&lex, Expr *&rex,
if (!Context.typesAreCompatible(
Context.getCanonicalType(lpointee).getUnqualifiedType(),
Context.getCanonicalType(rpointee).getUnqualifiedType())) {
Diag(Loc, diag::err_typecheck_sub_ptr_compatible,
lex->getType().getAsString(), rex->getType().getAsString(),
lex->getSourceRange(), rex->getSourceRange());
Diag(Loc, diag::err_typecheck_sub_ptr_compatible)
<< lex->getType().getAsString() << rex->getType().getAsString()
<< lex->getSourceRange() << rex->getSourceRange();
return QualType();
}
@ -2176,9 +2176,9 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
!Context.typesAreCompatible(LCanPointeeTy.getUnqualifiedType(),
RCanPointeeTy.getUnqualifiedType()) &&
!areComparableObjCInterfaces(LCanPointeeTy, RCanPointeeTy, Context)) {
Diag(Loc, diag::ext_typecheck_comparison_of_distinct_pointers,
lType.getAsString(), rType.getAsString(),
lex->getSourceRange(), rex->getSourceRange());
Diag(Loc, diag::ext_typecheck_comparison_of_distinct_pointers)
<< lType.getAsString() << rType.getAsString()
<< lex->getSourceRange() << rex->getSourceRange();
}
ImpCastExprToType(rex, lType); // promote the pointer to pointer
return Context.IntTy;
@ -2190,9 +2190,9 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
if (!LHSIsNull && !RHSIsNull &&
!Context.typesAreBlockCompatible(lpointee, rpointee)) {
Diag(Loc, diag::err_typecheck_comparison_of_distinct_blocks,
lType.getAsString(), rType.getAsString(),
lex->getSourceRange(), rex->getSourceRange());
Diag(Loc, diag::err_typecheck_comparison_of_distinct_blocks)
<< lType.getAsString() << rType.getAsString()
<< lex->getSourceRange() << rex->getSourceRange();
}
ImpCastExprToType(rex, lType); // promote the pointer to pointer
return Context.IntTy;
@ -2201,9 +2201,9 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
if ((lType->isBlockPointerType() && rType->isPointerType()) ||
(lType->isPointerType() && rType->isBlockPointerType())) {
if (!LHSIsNull && !RHSIsNull) {
Diag(Loc, diag::err_typecheck_comparison_of_distinct_blocks,
lType.getAsString(), rType.getAsString(),
lex->getSourceRange(), rex->getSourceRange());
Diag(Loc, diag::err_typecheck_comparison_of_distinct_blocks)
<< lType.getAsString() << rType.getAsString()
<< lex->getSourceRange() << rex->getSourceRange();
}
ImpCastExprToType(rex, lType); // promote the pointer to pointer
return Context.IntTy;
@ -2220,9 +2220,9 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
if (!LPtrToVoid && !RPtrToVoid &&
!Context.typesAreCompatible(lType, rType)) {
Diag(Loc, diag::ext_typecheck_comparison_of_distinct_pointers,
lType.getAsString(), rType.getAsString(),
lex->getSourceRange(), rex->getSourceRange());
Diag(Loc, diag::ext_typecheck_comparison_of_distinct_pointers)
<< lType.getAsString() << rType.getAsString()
<< lex->getSourceRange() << rex->getSourceRange();
ImpCastExprToType(rex, lType);
return Context.IntTy;
}
@ -2234,9 +2234,9 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
return Context.IntTy;
} else {
if ((lType->isObjCQualifiedIdType() && rType->isObjCQualifiedIdType())) {
Diag(Loc, diag::warn_incompatible_qualified_id_operands,
lType.getAsString(), rType.getAsString(),
lex->getSourceRange(), rex->getSourceRange());
Diag(Loc, diag::warn_incompatible_qualified_id_operands)
<< lType.getAsString() << rType.getAsString()
<< lex->getSourceRange() << rex->getSourceRange();
ImpCastExprToType(rex, lType);
return Context.IntTy;
}
@ -2245,35 +2245,35 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
if ((lType->isPointerType() || lType->isObjCQualifiedIdType()) &&
rType->isIntegerType()) {
if (!RHSIsNull)
Diag(Loc, diag::ext_typecheck_comparison_of_pointer_integer,
lType.getAsString(), rType.getAsString(),
lex->getSourceRange(), rex->getSourceRange());
Diag(Loc, diag::ext_typecheck_comparison_of_pointer_integer)
<< lType.getAsString() << rType.getAsString()
<< lex->getSourceRange() << rex->getSourceRange();
ImpCastExprToType(rex, lType); // promote the integer to pointer
return Context.IntTy;
}
if (lType->isIntegerType() &&
(rType->isPointerType() || rType->isObjCQualifiedIdType())) {
if (!LHSIsNull)
Diag(Loc, diag::ext_typecheck_comparison_of_pointer_integer,
lType.getAsString(), rType.getAsString(),
lex->getSourceRange(), rex->getSourceRange());
Diag(Loc, diag::ext_typecheck_comparison_of_pointer_integer)
<< lType.getAsString() << rType.getAsString()
<< lex->getSourceRange() << rex->getSourceRange();
ImpCastExprToType(lex, rType); // promote the integer to pointer
return Context.IntTy;
}
// Handle block pointers.
if (lType->isBlockPointerType() && rType->isIntegerType()) {
if (!RHSIsNull)
Diag(Loc, diag::ext_typecheck_comparison_of_pointer_integer,
lType.getAsString(), rType.getAsString(),
lex->getSourceRange(), rex->getSourceRange());
Diag(Loc, diag::ext_typecheck_comparison_of_pointer_integer)
<< lType.getAsString() << rType.getAsString()
<< lex->getSourceRange() << rex->getSourceRange();
ImpCastExprToType(rex, lType); // promote the integer to pointer
return Context.IntTy;
}
if (lType->isIntegerType() && rType->isBlockPointerType()) {
if (!LHSIsNull)
Diag(Loc, diag::ext_typecheck_comparison_of_pointer_integer,
lType.getAsString(), rType.getAsString(),
lex->getSourceRange(), rex->getSourceRange());
Diag(Loc, diag::ext_typecheck_comparison_of_pointer_integer)
<< lType.getAsString() << rType.getAsString()
<< lex->getSourceRange() << rex->getSourceRange();
ImpCastExprToType(lex, rType); // promote the integer to pointer
return Context.IntTy;
}
@ -3445,7 +3445,7 @@ bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy,
break;
}
Diag(Loc, DiagKind, DstType.getAsString(), SrcType.getAsString(), Flavor,
SrcExpr->getSourceRange());
Diag(Loc, DiagKind) << DstType.getAsString() << SrcType.getAsString()
<< Flavor << SrcExpr->getSourceRange();
return isInvalid;
}

View File

@ -204,8 +204,8 @@ Sema::CheckDerivedToBaseConversion(QualType Derived, QualType Base,
}
}
Diag(Loc, diag::err_ambiguous_derived_to_base_conv,
Derived.getAsString(), Base.getAsString(), PathDisplayStr, Range);
Diag(Loc, diag::err_ambiguous_derived_to_base_conv)
<< Derived.getAsString() << Base.getAsString() << PathDisplayStr << Range;
return true;
}

View File

@ -108,8 +108,9 @@ CheckConstCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
if (const ReferenceType *DestTypeTmp = DestType->getAsReferenceType()) {
if (SrcExpr->isLvalue(Self.Context) != Expr::LV_Valid) {
// Cannot cast non-lvalue to reference type.
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_rvalue,
"const_cast", OrigDestType.getAsString(), SrcExpr->getSourceRange());
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_rvalue)
<< "const_cast" << OrigDestType.getAsString()
<< SrcExpr->getSourceRange();
return;
}
@ -129,16 +130,16 @@ CheckConstCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
// Cannot cast to non-pointer, non-reference type. Note that, if DestType
// was a reference type, we converted it to a pointer above.
// C++ 5.2.11p3: For two pointer types [...]
Self.Diag(OpRange.getBegin(), diag::err_bad_const_cast_dest,
OrigDestType.getAsString(), DestRange);
Self.Diag(OpRange.getBegin(), diag::err_bad_const_cast_dest)
<< OrigDestType.getAsString() << DestRange;
return;
}
if (DestType->isFunctionPointerType()) {
// Cannot cast direct function pointers.
// C++ 5.2.11p2: [...] where T is any object type or the void type [...]
// T is the ultimate pointee of source and target type.
Self.Diag(OpRange.getBegin(), diag::err_bad_const_cast_dest,
OrigDestType.getAsString(), DestRange);
Self.Diag(OpRange.getBegin(), diag::err_bad_const_cast_dest)
<< OrigDestType.getAsString() << DestRange;
return;
}
SrcType = Self.Context.getCanonicalType(SrcType);
@ -169,9 +170,9 @@ CheckConstCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
{
if (SrcTypeArr->getSize() != DestTypeArr->getSize()) {
// Different array sizes.
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_generic,
"const_cast", OrigDestType.getAsString(), OrigSrcType.getAsString(),
OpRange);
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_generic)
<< "const_cast" << OrigDestType.getAsString()
<< OrigSrcType.getAsString() << OpRange;
return;
}
SrcType = SrcTypeArr->getElementType().getUnqualifiedType();
@ -182,8 +183,9 @@ CheckConstCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
// Since we're dealing in canonical types, the remainder must be the same.
if (SrcType != DestType) {
// Cast between unrelated types.
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_generic, "const_cast",
OrigDestType.getAsString(), OrigSrcType.getAsString(), OpRange);
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_generic)
<< "const_cast" << OrigDestType.getAsString()
<< OrigSrcType.getAsString() << OpRange;
return;
}
}
@ -204,9 +206,9 @@ CheckReinterpretCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
if (const ReferenceType *DestTypeTmp = DestType->getAsReferenceType()) {
if (SrcExpr->isLvalue(Self.Context) != Expr::LV_Valid) {
// Cannot cast non-lvalue to reference type.
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_rvalue,
"reinterpret_cast", OrigDestType.getAsString(),
SrcExpr->getSourceRange());
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_rvalue)
<< "reinterpret_cast" << OrigDestType.getAsString()
<< SrcExpr->getSourceRange();
return;
}
@ -233,9 +235,9 @@ CheckReinterpretCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
// Except for std::nullptr_t->integer, which is not supported yet, and
// lvalue->reference, which is handled above, at least one of the two
// arguments must be a pointer.
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_generic,
"reinterpret_cast", OrigDestType.getAsString(), OrigSrcType.getAsString(),
OpRange);
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_generic)
<< "reinterpret_cast" << OrigDestType.getAsString()
<< OrigSrcType.getAsString() << OpRange;
return;
}
@ -257,8 +259,8 @@ CheckReinterpretCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
// type large enough to hold it.
if (Self.Context.getTypeSize(SrcType) >
Self.Context.getTypeSize(DestType)) {
Self.Diag(OpRange.getBegin(), diag::err_bad_reinterpret_cast_small_int,
OrigDestType.getAsString(), DestRange);
Self.Diag(OpRange.getBegin(), diag::err_bad_reinterpret_cast_small_int)
<< OrigDestType.getAsString() << DestRange;
}
return;
}
@ -273,17 +275,17 @@ CheckReinterpretCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
if (!destIsPtr || !srcIsPtr) {
// With the valid non-pointer conversions out of the way, we can be even
// more stringent.
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_generic,
"reinterpret_cast", OrigDestType.getAsString(), OrigSrcType.getAsString(),
OpRange);
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_generic)
<< "reinterpret_cast" << OrigDestType.getAsString()
<< OrigSrcType.getAsString() << OpRange;
return;
}
// C++ 5.2.10p2: The reinterpret_cast operator shall not cast away constness.
if (CastsAwayConstness(Self, SrcType, DestType)) {
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_const_away,
"reinterpret_cast", OrigDestType.getAsString(), OrigSrcType.getAsString(),
OpRange);
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_const_away)
<< "reinterpret_cast" << OrigDestType.getAsString()
<< OrigSrcType.getAsString() << OpRange;
return;
}
@ -306,7 +308,8 @@ CheckReinterpretCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
// FIXME: Conditionally-supported behavior should be configurable in the
// TargetInfo or similar.
if (!Self.getLangOptions().CPlusPlus0x) {
Self.Diag(OpRange.getBegin(), diag::ext_reinterpret_cast_fn_obj, OpRange);
Self.Diag(OpRange.getBegin(), diag::ext_reinterpret_cast_fn_obj)
<< OpRange;
}
return;
}
@ -316,7 +319,8 @@ CheckReinterpretCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
if (DestType->isFunctionPointerType()) {
// See above.
if (!Self.getLangOptions().CPlusPlus0x) {
Self.Diag(OpRange.getBegin(), diag::ext_reinterpret_cast_fn_obj, OpRange);
Self.Diag(OpRange.getBegin(), diag::ext_reinterpret_cast_fn_obj)
<< OpRange;
}
return;
}
@ -462,9 +466,9 @@ CheckStaticCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
// This is definitely the intended conversion, but it might fail due
// to a const violation.
if (!DestPointee.isAtLeastAsQualifiedAs(SrcPointee)) {
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_const_away,
"static_cast", DestType.getAsString(),
OrigSrcType.getAsString(), OpRange);
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_const_away)
<< "static_cast" << DestType.getAsString()
<< OrigSrcType.getAsString() << OpRange;
}
return;
}
@ -476,8 +480,9 @@ CheckStaticCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
// FIXME: Error reporting could be a lot better. Should store the reason
// why every substep failed and, at the end, select the most specific and
// report that.
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_generic, "static_cast",
DestType.getAsString(), OrigSrcType.getAsString(), OpRange);
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_generic)
<< "static_cast" << DestType.getAsString() << OrigSrcType.getAsString()
<< OpRange;
}
/// Tests whether a conversion according to C++ 5.2.9p5 is valid.
@ -575,9 +580,9 @@ TryStaticDowncast(Sema &Self, QualType SrcType, QualType DestType,
// Must preserve cv, as always.
if (!DestType.isAtLeastAsQualifiedAs(SrcType)) {
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_const_away,
"static_cast", OrigDestType.getAsString(), OrigSrcType.getAsString(),
OpRange);
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_const_away)
<< "static_cast" << OrigDestType.getAsString()
<< OrigSrcType.getAsString() << OpRange;
return TSC_Failed;
}
@ -604,18 +609,18 @@ TryStaticDowncast(Sema &Self, QualType SrcType, QualType DestType,
}
}
Self.Diag(OpRange.getBegin(), diag::err_ambiguous_base_to_derived_cast,
SrcType.getUnqualifiedType().getAsString(),
DestType.getUnqualifiedType().getAsString(),
PathDisplayStr, OpRange);
Self.Diag(OpRange.getBegin(), diag::err_ambiguous_base_to_derived_cast)
<< SrcType.getUnqualifiedType().getAsString()
<< DestType.getUnqualifiedType().getAsString()
<< PathDisplayStr << OpRange;
return TSC_Failed;
}
if (Paths.getDetectedVirtual() != 0) {
QualType VirtualBase(Paths.getDetectedVirtual(), 0);
Self.Diag(OpRange.getBegin(), diag::err_static_downcast_via_virtual,
OrigSrcType.getAsString(), OrigDestType.getAsString(),
VirtualBase.getAsString(), OpRange);
Self.Diag(OpRange.getBegin(), diag::err_static_downcast_via_virtual)
<< OrigSrcType.getAsString() << OrigDestType.getAsString()
<< VirtualBase.getAsString() << OpRange;
return TSC_Failed;
}
@ -674,8 +679,8 @@ CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
} else if (DestReference) {
DestPointee = DestReference->getPointeeType();
} else {
Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_ref_or_ptr,
OrigDestType.getAsString(), DestRange);
Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_ref_or_ptr)
<< OrigDestType.getAsString() << DestRange;
return;
}
@ -684,13 +689,13 @@ CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
assert(DestPointer && "Reference to void is not possible");
} else if (DestRecord) {
if (!DestRecord->getDecl()->isDefinition()) {
Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_incomplete,
DestPointee.getUnqualifiedType().getAsString(), DestRange);
Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_incomplete)
<< DestPointee.getUnqualifiedType().getAsString() << DestRange;
return;
}
} else {
Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_class,
DestPointee.getUnqualifiedType().getAsString(), DestRange);
Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_class)
<< DestPointee.getUnqualifiedType().getAsString() << DestRange;
return;
}
@ -704,14 +709,14 @@ CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
if (const PointerType *SrcPointer = SrcType->getAsPointerType()) {
SrcPointee = SrcPointer->getPointeeType();
} else {
Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_ptr,
OrigSrcType.getAsString(), SrcExpr->getSourceRange());
Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_ptr)
<< OrigSrcType.getAsString() << SrcExpr->getSourceRange();
return;
}
} else {
if (SrcExpr->isLvalue(Self.Context) != Expr::LV_Valid) {
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_rvalue,
"dynamic_cast", OrigDestType.getAsString(), OpRange);
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_rvalue)
<< "dynamic_cast" << OrigDestType.getAsString() << OpRange;
}
SrcPointee = SrcType;
}
@ -719,9 +724,9 @@ CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
const RecordType *SrcRecord = SrcPointee->getAsRecordType();
if (SrcRecord) {
if (!SrcRecord->getDecl()->isDefinition()) {
Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_incomplete,
SrcPointee.getUnqualifiedType().getAsString(),
SrcExpr->getSourceRange());
Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_incomplete)
<< SrcPointee.getUnqualifiedType().getAsString()
<< SrcExpr->getSourceRange();
return;
}
} else {
@ -739,9 +744,9 @@ CheckDynamicCast(Sema &Self, Expr *&SrcExpr, QualType DestType,
// C++ 5.2.7p1: The dynamic_cast operator shall not cast away constness.
if (!DestPointee.isAtLeastAsQualifiedAs(SrcPointee)) {
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_const_away,
"dynamic_cast", OrigDestType.getAsString(), OrigSrcType.getAsString(),
OpRange);
Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_const_away)
<< "dynamic_cast" << OrigDestType.getAsString()
<< OrigSrcType.getAsString() << OpRange;
return;
}

View File

@ -1405,10 +1405,9 @@ bool Sema::PerformCopyInitialization(Expr *&From, QualType ToType,
} else {
if (PerformImplicitConversion(From, ToType))
return Diag(From->getSourceRange().getBegin(),
diag::err_typecheck_convert_incompatible,
ToType.getAsString(), From->getType().getAsString(),
Flavor,
From->getSourceRange());
diag::err_typecheck_convert_incompatible)
<< ToType.getAsString() << From->getType().getAsString()
<< Flavor << From->getSourceRange();
else
return false;
}