From: Douglas Gregor Date: Fri, 4 May 2012 16:48:41 +0000 (+0000) Subject: Switch RequireLiteralType() off of PartialDiagnostic. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f502d8ec9b43b259db9e37e9622279df46070fed;p=clang Switch RequireLiteralType() off of PartialDiagnostic. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156178 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index e300a858e0..d0143f0bef 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -945,16 +945,17 @@ public: ParsedType ActOnObjCInstanceType(SourceLocation Loc); /// \brief Abstract class used to diagnose incomplete types. - struct IncompleteTypeDiagnoser { + struct TypeDiagnoser { bool Suppressed; - IncompleteTypeDiagnoser(bool Suppressed = false) : Suppressed(Suppressed) { } + TypeDiagnoser(bool Suppressed = false) : Suppressed(Suppressed) { } virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0; - virtual ~IncompleteTypeDiagnoser() {} + virtual ~TypeDiagnoser() {} }; static int getPrintable(int I) { return I; } + static unsigned getPrintable(unsigned I) { return I; } static bool getPrintable(bool B) { return B; } static const char * getPrintable(const char *S) { return S; } static StringRef getPrintable(StringRef S) { return S; } @@ -970,31 +971,31 @@ public: static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange();} template - class BoundIncompleteTypeDiagnoser1 : public IncompleteTypeDiagnoser { + class BoundTypeDiagnoser1 : public TypeDiagnoser { unsigned DiagID; const T1 &Arg1; public: - BoundIncompleteTypeDiagnoser1(unsigned DiagID, const T1 &Arg1) - : IncompleteTypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1) { } + BoundTypeDiagnoser1(unsigned DiagID, const T1 &Arg1) + : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1) { } virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) { if (Suppressed) return; S.Diag(Loc, DiagID) << getPrintable(Arg1) << T; } - virtual ~BoundIncompleteTypeDiagnoser1() { } + virtual ~BoundTypeDiagnoser1() { } }; template - class BoundIncompleteTypeDiagnoser2 : public IncompleteTypeDiagnoser { + class BoundTypeDiagnoser2 : public TypeDiagnoser { unsigned DiagID; const T1 &Arg1; const T2 &Arg2; public: - BoundIncompleteTypeDiagnoser2(unsigned DiagID, const T1 &Arg1, + BoundTypeDiagnoser2(unsigned DiagID, const T1 &Arg1, const T2 &Arg2) - : IncompleteTypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1), + : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1), Arg2(Arg2) { } virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) { @@ -1002,20 +1003,20 @@ public: S.Diag(Loc, DiagID) << getPrintable(Arg1) << getPrintable(Arg2) << T; } - virtual ~BoundIncompleteTypeDiagnoser2() { } + virtual ~BoundTypeDiagnoser2() { } }; template - class BoundIncompleteTypeDiagnoser3 : public IncompleteTypeDiagnoser { + class BoundTypeDiagnoser3 : public TypeDiagnoser { unsigned DiagID; const T1 &Arg1; const T2 &Arg2; const T3 &Arg3; public: - BoundIncompleteTypeDiagnoser3(unsigned DiagID, const T1 &Arg1, + BoundTypeDiagnoser3(unsigned DiagID, const T1 &Arg1, const T2 &Arg2, const T3 &Arg3) - : IncompleteTypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1), + : TypeDiagnoser(DiagID == 0), DiagID(DiagID), Arg1(Arg1), Arg2(Arg2), Arg3(Arg3) { } virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) { @@ -1024,25 +1025,25 @@ public: << getPrintable(Arg1) << getPrintable(Arg2) << getPrintable(Arg3) << T; } - virtual ~BoundIncompleteTypeDiagnoser3() { } + virtual ~BoundTypeDiagnoser3() { } }; bool RequireCompleteType(SourceLocation Loc, QualType T, - IncompleteTypeDiagnoser &Diagnoser); + TypeDiagnoser &Diagnoser); bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID); template bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID, const T1 &Arg1) { - BoundIncompleteTypeDiagnoser1 Diagnoser(DiagID, Arg1); + BoundTypeDiagnoser1 Diagnoser(DiagID, Arg1); return RequireCompleteType(Loc, T, Diagnoser); } template bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID, const T1 &Arg1, const T2 &Arg2) { - BoundIncompleteTypeDiagnoser2 Diagnoser(DiagID, Arg1, Arg2); + BoundTypeDiagnoser2 Diagnoser(DiagID, Arg1, Arg2); return RequireCompleteType(Loc, T, Diagnoser); } @@ -1050,37 +1051,61 @@ public: bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID, const T1 &Arg1, const T2 &Arg2, const T3 &Arg3) { - BoundIncompleteTypeDiagnoser3 Diagnoser(DiagID, Arg1, Arg2, + BoundTypeDiagnoser3 Diagnoser(DiagID, Arg1, Arg2, Arg3); return RequireCompleteType(Loc, T, Diagnoser); } - bool RequireCompleteExprType(Expr *E, IncompleteTypeDiagnoser &Diagnoser); + bool RequireCompleteExprType(Expr *E, TypeDiagnoser &Diagnoser); bool RequireCompleteExprType(Expr *E, unsigned DiagID); template bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1) { - BoundIncompleteTypeDiagnoser1 Diagnoser(DiagID, Arg1); + BoundTypeDiagnoser1 Diagnoser(DiagID, Arg1); return RequireCompleteExprType(E, Diagnoser); } template bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1, const T2 &Arg2) { - BoundIncompleteTypeDiagnoser2 Diagnoser(DiagID, Arg1, Arg2); + BoundTypeDiagnoser2 Diagnoser(DiagID, Arg1, Arg2); return RequireCompleteExprType(E, Diagnoser); } template bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1, const T2 &Arg2, const T3 &Arg3) { - BoundIncompleteTypeDiagnoser3 Diagnoser(DiagID, Arg1, Arg2, + BoundTypeDiagnoser3 Diagnoser(DiagID, Arg1, Arg2, Arg3); return RequireCompleteExprType(E, Diagnoser); } bool RequireLiteralType(SourceLocation Loc, QualType T, - const PartialDiagnostic &PD); + TypeDiagnoser &Diagnoser); + bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID); + + template + bool RequireLiteralType(SourceLocation Loc, QualType T, + unsigned DiagID, const T1 &Arg1) { + BoundTypeDiagnoser1 Diagnoser(DiagID, Arg1); + return RequireLiteralType(Loc, T, Diagnoser); + } + + template + bool RequireLiteralType(SourceLocation Loc, QualType T, + unsigned DiagID, const T1 &Arg1, const T2 &Arg2) { + BoundTypeDiagnoser2 Diagnoser(DiagID, Arg1, Arg2); + return RequireLiteralType(Loc, T, Diagnoser); + } + + template + bool RequireLiteralType(SourceLocation Loc, QualType T, + unsigned DiagID, const T1 &Arg1, const T2 &Arg2, + const T3 &Arg3) { + BoundTypeDiagnoser3 Diagnoser(DiagID, Arg1, Arg2, + Arg3); + return RequireLiteralType(Loc, T, Diagnoser); + } QualType getElaboratedType(ElaboratedTypeKeyword Keyword, const CXXScopeSpec &SS, QualType T); diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 1480b3ea57..d1cc73c3f8 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4452,7 +4452,7 @@ bool Sema::CheckVariableDeclaration(VarDecl *NewVD, if (NewVD->isConstexpr() && !T->isDependentType() && RequireLiteralType(NewVD->getLocation(), T, - PDiag(diag::err_constexpr_var_non_literal))) { + diag::err_constexpr_var_non_literal)) { NewVD->setInvalidDecl(); return false; } diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 5e466adc5f..c35b8af85f 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -667,9 +667,9 @@ static bool CheckConstexprParameterTypes(Sema &SemaRef, SourceLocation ParamLoc = PD->getLocation(); if (!(*i)->isDependentType() && SemaRef.RequireLiteralType(ParamLoc, *i, - SemaRef.PDiag(diag::err_constexpr_non_literal_param) - << ArgIndex+1 << PD->getSourceRange() - << isa(FD))) + diag::err_constexpr_non_literal_param, + ArgIndex+1, PD->getSourceRange(), + isa(FD))) return false; } return true; @@ -725,7 +725,7 @@ bool Sema::CheckConstexprFunctionDecl(const FunctionDecl *NewFD) { QualType RT = NewFD->getResultType(); if (!RT->isDependentType() && RequireLiteralType(NewFD->getLocation(), RT, - PDiag(diag::err_constexpr_non_literal_return))) + diag::err_constexpr_non_literal_return)) return false; } @@ -3762,7 +3762,7 @@ void Sema::CheckCompletedCXXClass(CXXRecordDecl *Record) { case TSK_Undeclared: case TSK_ExplicitSpecialization: RequireLiteralType(M->getLocation(), Context.getRecordType(Record), - PDiag(diag::err_constexpr_method_non_literal)); + diag::err_constexpr_method_non_literal); break; } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index ce4bffa1cb..3af9ab42c3 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -10663,7 +10663,7 @@ bool Sema::CheckCallReturnType(QualType ReturnType, SourceLocation Loc, return false; } - class CallReturnIncompleteDiagnoser : public IncompleteTypeDiagnoser { + class CallReturnIncompleteDiagnoser : public TypeDiagnoser { FunctionDecl *FD; CallExpr *CE; diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index a3a963f356..fb8ab47df6 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -5061,11 +5061,11 @@ Sema::ConvertToIntegralOrEnumerationType(SourceLocation Loc, Expr *From, } // We must have a complete class type. - struct IncompleteTypeDiagnoserPartialDiag : IncompleteTypeDiagnoser { + struct TypeDiagnoserPartialDiag : TypeDiagnoser { const PartialDiagnostic &PD; - IncompleteTypeDiagnoserPartialDiag(const PartialDiagnostic &PD) - : IncompleteTypeDiagnoser(PD.getDiagID() == 0), PD(PD) {} + TypeDiagnoserPartialDiag(const PartialDiagnostic &PD) + : TypeDiagnoser(PD.getDiagID() == 0), PD(PD) {} virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) { S.Diag(Loc, PD) << T; diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index c81ace1287..09e4ec8375 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -4048,7 +4048,7 @@ static void processTypeAttrs(TypeProcessingState &state, QualType &type, /// /// \returns \c true if the type of \p E is incomplete and diagnosed, \c false /// otherwise. -bool Sema::RequireCompleteExprType(Expr *E, IncompleteTypeDiagnoser &Diagnoser){ +bool Sema::RequireCompleteExprType(Expr *E, TypeDiagnoser &Diagnoser){ QualType T = E->getType(); // Fast path the case where the type is already complete. @@ -4109,11 +4109,11 @@ bool Sema::RequireCompleteExprType(Expr *E, IncompleteTypeDiagnoser &Diagnoser){ } namespace { - struct IncompleteTypeDiagnoserDiag : Sema::IncompleteTypeDiagnoser { + struct TypeDiagnoserDiag : Sema::TypeDiagnoser { unsigned DiagID; - IncompleteTypeDiagnoserDiag(unsigned DiagID) - : Sema::IncompleteTypeDiagnoser(DiagID == 0), DiagID(DiagID) {} + TypeDiagnoserDiag(unsigned DiagID) + : Sema::TypeDiagnoser(DiagID == 0), DiagID(DiagID) {} virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) { if (Suppressed) return; @@ -4123,7 +4123,7 @@ namespace { } bool Sema::RequireCompleteExprType(Expr *E, unsigned DiagID) { - IncompleteTypeDiagnoserDiag Diagnoser(DiagID); + TypeDiagnoserDiag Diagnoser(DiagID); return RequireCompleteExprType(E, Diagnoser); } @@ -4148,7 +4148,7 @@ bool Sema::RequireCompleteExprType(Expr *E, unsigned DiagID) { /// @returns @c true if @p T is incomplete and a diagnostic was emitted, /// @c false otherwise. bool Sema::RequireCompleteType(SourceLocation Loc, QualType T, - IncompleteTypeDiagnoser &Diagnoser) { + TypeDiagnoser &Diagnoser) { // FIXME: Add this assertion to make sure we always get instantiation points. // assert(!Loc.isInvalid() && "Invalid location in RequireCompleteType"); // FIXME: Add this assertion to help us flush out problems with @@ -4257,7 +4257,7 @@ bool Sema::RequireCompleteType(SourceLocation Loc, QualType T, bool Sema::RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID) { - IncompleteTypeDiagnoserDiag Diagnoser(DiagID); + TypeDiagnoserDiag Diagnoser(DiagID); return RequireCompleteType(Loc, T, Diagnoser); } @@ -4275,13 +4275,12 @@ bool Sema::RequireCompleteType(SourceLocation Loc, QualType T, /// /// @param T The type that this routine is examining for literalness. /// -/// @param PD The partial diagnostic that will be printed out if T is not a -/// literal type. +/// @param Diagnoser Emits a diagnostic if T is not a literal type. /// /// @returns @c true if @p T is not a literal type and a diagnostic was emitted, /// @c false otherwise. bool Sema::RequireLiteralType(SourceLocation Loc, QualType T, - const PartialDiagnostic &PD) { + TypeDiagnoser &Diagnoser) { assert(!T->isDependentType() && "type should not be dependent"); QualType ElemType = Context.getBaseElementType(T); @@ -4290,10 +4289,10 @@ bool Sema::RequireLiteralType(SourceLocation Loc, QualType T, if (T->isLiteralType()) return false; - if (PD.getDiagID() == 0) + if (Diagnoser.Suppressed) return true; - Diag(Loc, PD) << T; + Diagnoser.diagnose(*this, Loc, T); if (T->isVariableArrayType()) return true; @@ -4362,6 +4361,11 @@ bool Sema::RequireLiteralType(SourceLocation Loc, QualType T, return true; } +bool Sema::RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID) { + TypeDiagnoserDiag Diagnoser(DiagID); + return RequireLiteralType(Loc, T, Diagnoser); +} + /// \brief Retrieve a version of the type 'T' that is elaborated by Keyword /// and qualified by the nested-name-specifier contained in SS. QualType Sema::getElaboratedType(ElaboratedTypeKeyword Keyword,