]> granicus.if.org Git - clang/commitdiff
Add a new, more advanced CheckDerivedToBaseConversion that takes custom diagnostic...
authorAnders Carlsson <andersca@mac.com>
Wed, 13 May 2009 21:11:42 +0000 (21:11 +0000)
committerAnders Carlsson <andersca@mac.com>
Wed, 13 May 2009 21:11:42 +0000 (21:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71720 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaAccess.cpp
lib/Sema/SemaInherit.cpp

index 9d5afbbb9c907e6b06119713e0d716f58635e0b5..08f9b02d77f35fb817a190f4d2bd2a0cd2dd5560 100644 (file)
@@ -1773,6 +1773,12 @@ public:
                      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 @@ public:
                                 AccessSpecifier LexicalAS);
   
   bool CheckBaseClassAccess(QualType Derived, QualType Base, 
-                            BasePaths& Paths, SourceLocation AccessLoc);
+                            unsigned InaccessibleBaseID,
+                            BasePaths& Paths, SourceLocation AccessLoc,
+                            DeclarationName Name);
   
   
   enum AbstractDiagSelID {
index b832d38d1d8b5e9f01cbd4ac6deb51d0fcd941da..bae69ac6dc74aa7089ea4e4b5ccfa0ebef7d5de9 100644 (file)
@@ -46,7 +46,9 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl,
 /// 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 @@ bool Sema::CheckBaseClassAccess(QualType Derived, QualType Base,
   }
 
   if (InacessibleBase) {
-    Diag(AccessLoc, diag::err_conv_to_inaccessible_base
-      << Derived << Base;
+    Diag(AccessLoc, InaccessibleBaseID
+      << Derived << Base << Name;
 
     AccessSpecifier AS = InacessibleBase->getAccessSpecifierAsWritten();
     
index 8239f54d68a7b03d0940f7f5ab99112992224bb2..1f3433e16698cc08a47936118ebb0b7c9f73d989 100644 (file)
@@ -236,9 +236,12 @@ bool Sema::LookupInBases(CXXRecordDecl *Class,
 /// 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 @@ Sema::CheckDerivedToBaseConversion(QualType Derived, QualType Base,
 
   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 @@ Sema::CheckDerivedToBaseConversion(QualType Derived, QualType Base,
   // 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.