[cfe-commits] r156178 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaOverload.cpp lib/Sema/SemaType.cpp

Douglas Gregor dgregor at apple.com
Fri May 4 09:48:41 PDT 2012


Author: dgregor
Date: Fri May  4 11:48:41 2012
New Revision: 156178

URL: http://llvm.org/viewvc/llvm-project?rev=156178&view=rev
Log:
Switch RequireLiteralType() off of PartialDiagnostic.

Modified:
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=156178&r1=156177&r2=156178&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri May  4 11:48:41 2012
@@ -945,16 +945,17 @@
   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 @@
   static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange();}
   
   template<typename T1>
-  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<typename T1, typename T2>
-  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 @@
       S.Diag(Loc, DiagID) << getPrintable(Arg1) << getPrintable(Arg2) << T;
     }
     
-    virtual ~BoundIncompleteTypeDiagnoser2() { }
+    virtual ~BoundTypeDiagnoser2() { }
   };
 
   template<typename T1, typename T2, typename T3>
-  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 @@
         << 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<typename T1>
   bool RequireCompleteType(SourceLocation Loc, QualType T,
                            unsigned DiagID, const T1 &Arg1) {
-    BoundIncompleteTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
+    BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
     return RequireCompleteType(Loc, T, Diagnoser);
   }
   
   template<typename T1, typename T2>
   bool RequireCompleteType(SourceLocation Loc, QualType T,
                            unsigned DiagID, const T1 &Arg1, const T2 &Arg2) {
-    BoundIncompleteTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
+    BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
     return RequireCompleteType(Loc, T, Diagnoser);
   }
 
@@ -1050,37 +1051,61 @@
   bool RequireCompleteType(SourceLocation Loc, QualType T,
                            unsigned DiagID, const T1 &Arg1, const T2 &Arg2,
                            const T3 &Arg3) {
-    BoundIncompleteTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2,
+    BoundTypeDiagnoser3<T1, T2, T3> 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<typename T1>
   bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1) {
-    BoundIncompleteTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
+    BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
     return RequireCompleteExprType(E, Diagnoser);
   }
 
   template<typename T1, typename T2>
   bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1,
                                const T2 &Arg2) {
-    BoundIncompleteTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
+    BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
     return RequireCompleteExprType(E, Diagnoser);
   }
 
   template<typename T1, typename T2, typename T3>
   bool RequireCompleteExprType(Expr *E, unsigned DiagID, const T1 &Arg1,
                                const T2 &Arg2, const T3 &Arg3) {
-    BoundIncompleteTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2,
+    BoundTypeDiagnoser3<T1, T2, T3> 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<typename T1>
+  bool RequireLiteralType(SourceLocation Loc, QualType T,
+                          unsigned DiagID, const T1 &Arg1) {
+    BoundTypeDiagnoser1<T1> Diagnoser(DiagID, Arg1);
+    return RequireLiteralType(Loc, T, Diagnoser);
+  }
+
+  template<typename T1, typename T2>
+  bool RequireLiteralType(SourceLocation Loc, QualType T,
+                          unsigned DiagID, const T1 &Arg1, const T2 &Arg2) {
+    BoundTypeDiagnoser2<T1, T2> Diagnoser(DiagID, Arg1, Arg2);
+    return RequireLiteralType(Loc, T, Diagnoser);
+  }
+
+  template<typename T1, typename T2, typename T3>
+  bool RequireLiteralType(SourceLocation Loc, QualType T,
+                          unsigned DiagID, const T1 &Arg1, const T2 &Arg2,
+                          const T3 &Arg3) {
+    BoundTypeDiagnoser3<T1, T2, T3> Diagnoser(DiagID, Arg1, Arg2,
+                                                        Arg3);
+    return RequireLiteralType(Loc, T, Diagnoser);
+  }
 
   QualType getElaboratedType(ElaboratedTypeKeyword Keyword,
                              const CXXScopeSpec &SS, QualType T);

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=156178&r1=156177&r2=156178&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri May  4 11:48:41 2012
@@ -4452,7 +4452,7 @@
 
   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;
   }

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=156178&r1=156177&r2=156178&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri May  4 11:48:41 2012
@@ -667,9 +667,9 @@
     SourceLocation ParamLoc = PD->getLocation();
     if (!(*i)->isDependentType() &&
         SemaRef.RequireLiteralType(ParamLoc, *i,
-                            SemaRef.PDiag(diag::err_constexpr_non_literal_param)
-                                     << ArgIndex+1 << PD->getSourceRange()
-                                     << isa<CXXConstructorDecl>(FD)))
+                                   diag::err_constexpr_non_literal_param,
+                                   ArgIndex+1, PD->getSourceRange(),
+                                   isa<CXXConstructorDecl>(FD)))
       return false;
   }
   return true;
@@ -725,7 +725,7 @@
     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 @@
         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;
         }
 

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=156178&r1=156177&r2=156178&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri May  4 11:48:41 2012
@@ -10663,7 +10663,7 @@
     return false;
   }
 
-  class CallReturnIncompleteDiagnoser : public IncompleteTypeDiagnoser {
+  class CallReturnIncompleteDiagnoser : public TypeDiagnoser {
     FunctionDecl *FD;
     CallExpr *CE;
     

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=156178&r1=156177&r2=156178&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri May  4 11:48:41 2012
@@ -5061,11 +5061,11 @@
   }
 
   // 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;

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=156178&r1=156177&r2=156178&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Fri May  4 11:48:41 2012
@@ -4048,7 +4048,7 @@
 ///
 /// \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 @@
 }
 
 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 @@
 }
 
 bool Sema::RequireCompleteExprType(Expr *E, unsigned DiagID) {
-  IncompleteTypeDiagnoserDiag Diagnoser(DiagID);
+  TypeDiagnoserDiag Diagnoser(DiagID);
   return RequireCompleteExprType(E, Diagnoser);
 }
 
@@ -4148,7 +4148,7 @@
 /// @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,
                                unsigned DiagID) {  
-  IncompleteTypeDiagnoserDiag Diagnoser(DiagID);
+  TypeDiagnoserDiag Diagnoser(DiagID);
   return RequireCompleteType(Loc, T, Diagnoser);
 }
 
@@ -4275,13 +4275,12 @@
 ///
 /// @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 @@
   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 @@
   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,





More information about the cfe-commits mailing list