[cfe-commits] r71720 - in /cfe/trunk/lib/Sema: Sema.h SemaAccess.cpp SemaInherit.cpp

Anders Carlsson andersca at mac.com
Wed May 13 14:11:47 PDT 2009


Author: andersca
Date: Wed May 13 16:11:42 2009
New Revision: 71720

URL: http://llvm.org/viewvc/llvm-project?rev=71720&view=rev
Log:
Add a new, more advanced CheckDerivedToBaseConversion that takes custom diagnostic IDs.

Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaAccess.cpp
    cfe/trunk/lib/Sema/SemaInherit.cpp

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=71720&r1=71719&r2=71720&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed May 13 16:11:42 2009
@@ -1773,6 +1773,12 @@
                      BasePaths &Paths);
   bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
                                     SourceLocation Loc, SourceRange Range);
+  bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
+                                    unsigned InaccessibleBaseID,
+                                    unsigned AmbigiousBaseConvID,
+                                    SourceLocation Loc, SourceRange Range,
+                                    DeclarationName Name);
+  
   std::string getAmbiguousPathsDisplayString(BasePaths &Paths);
 
   //===--------------------------------------------------------------------===//
@@ -1784,7 +1790,9 @@
                                 AccessSpecifier LexicalAS);
   
   bool CheckBaseClassAccess(QualType Derived, QualType Base, 
-                            BasePaths& Paths, SourceLocation AccessLoc);
+                            unsigned InaccessibleBaseID,
+                            BasePaths& Paths, SourceLocation AccessLoc,
+                            DeclarationName Name);
   
   
   enum AbstractDiagSelID {

Modified: cfe/trunk/lib/Sema/SemaAccess.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAccess.cpp?rev=71720&r1=71719&r2=71720&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaAccess.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAccess.cpp Wed May 13 16:11:42 2009
@@ -46,7 +46,9 @@
 /// CheckBaseClassAccess - Check that a derived class can access its base class
 /// and report an error if it can't. [class.access.base]
 bool Sema::CheckBaseClassAccess(QualType Derived, QualType Base, 
-                                BasePaths& Paths, SourceLocation AccessLoc) {
+                                unsigned InaccessibleBaseID,
+                                BasePaths& Paths, SourceLocation AccessLoc,
+                                DeclarationName Name) {
   Base = Context.getCanonicalType(Base).getUnqualifiedType();
   assert(!Paths.isAmbiguous(Base) && 
          "Can't check base class access if set of paths is ambiguous");
@@ -101,8 +103,8 @@
   }
 
   if (InacessibleBase) {
-    Diag(AccessLoc, diag::err_conv_to_inaccessible_base) 
-      << Derived << Base;
+    Diag(AccessLoc, InaccessibleBaseID) 
+      << Derived << Base << Name;
 
     AccessSpecifier AS = InacessibleBase->getAccessSpecifierAsWritten();
     

Modified: cfe/trunk/lib/Sema/SemaInherit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInherit.cpp?rev=71720&r1=71719&r2=71720&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaInherit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInherit.cpp Wed May 13 16:11:42 2009
@@ -236,9 +236,12 @@
 /// otherwise. Loc is the location where this routine should point to
 /// if there is an error, and Range is the source range to highlight
 /// if there is an error.
-bool 
+bool
 Sema::CheckDerivedToBaseConversion(QualType Derived, QualType Base,
-                                   SourceLocation Loc, SourceRange Range) {
+                                   unsigned InaccessibleBaseID,
+                                   unsigned AmbigiousBaseConvID,
+                                   SourceLocation Loc, SourceRange Range,
+                                   DeclarationName Name) {
   // First, determine whether the path from Derived to Base is
   // ambiguous. This is slightly more expensive than checking whether
   // the Derived to Base conversion exists, because here we need to
@@ -252,7 +255,8 @@
 
   if (!Paths.isAmbiguous(Context.getCanonicalType(Base).getUnqualifiedType())) {
     // Check that the base class can be accessed.
-    return CheckBaseClassAccess(Derived, Base, Paths, Loc);
+    return CheckBaseClassAccess(Derived, Base, InaccessibleBaseID, Paths, Loc,
+                                Name);
   }
 
   // We know that the derived-to-base conversion is ambiguous, and
@@ -273,11 +277,21 @@
   // to each base class subobject.
   std::string PathDisplayStr = getAmbiguousPathsDisplayString(Paths);
   
-  Diag(Loc, diag::err_ambiguous_derived_to_base_conv)
-    << Derived << Base << PathDisplayStr << Range;
+  Diag(Loc, AmbigiousBaseConvID)
+    << Derived << Base << PathDisplayStr << Range << Name;
   return true;
 }
 
+bool 
+Sema::CheckDerivedToBaseConversion(QualType Derived, QualType Base,
+                                   SourceLocation Loc, SourceRange Range) {
+  return CheckDerivedToBaseConversion(Derived, Base, 
+                                      diag::err_conv_to_inaccessible_base,
+                                      diag::err_ambiguous_derived_to_base_conv,
+                                      Loc, Range, DeclarationName());
+}
+                                      
+
 /// @brief Builds a string representing ambiguous paths from a
 /// specific derived class to different subobjects of the same base
 /// class.





More information about the cfe-commits mailing list