[cfe-commits] r58096 - in /cfe/trunk/lib/Sema: Sema.h SemaExprCXX.cpp SemaInherit.cpp SemaOverload.cpp
Douglas Gregor
doug.gregor at gmail.com
Fri Oct 24 09:17:20 PDT 2008
Author: dgregor
Date: Fri Oct 24 11:17:19 2008
New Revision: 58096
URL: http://llvm.org/viewvc/llvm-project?rev=58096&view=rev
Log:
Some cleanups for the ambiguous derived-to-base conversion checks
Modified:
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaInherit.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=58096&r1=58095&r2=58096&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Fri Oct 24 11:17:19 2008
@@ -798,8 +798,8 @@
bool IsDerivedFrom(QualType Derived, QualType Base);
bool IsDerivedFrom(QualType Derived, QualType Base, BasePaths &Paths);
- bool CheckDerivedToBaseConversion(SourceLocation Loc, SourceRange Range,
- QualType Derived, QualType Base);
+ bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
+ SourceLocation Loc, SourceRange Range);
// Objective-C declarations.
virtual DeclTy *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=58096&r1=58095&r2=58096&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Oct 24 11:17:19 2008
@@ -287,9 +287,10 @@
// object pointers.
}
-/// Check if the pointer conversion from SrcType to DestType casts away
-/// constness as defined in C++ 5.2.11p8ff. This is used by the cast checkers.
-/// Both arguments must denote pointer types.
+/// CastsAwayConstness - Check if the pointer conversion from SrcType
+/// to DestType casts away constness as defined in C++
+/// 5.2.11p8ff. This is used by the cast checkers. Both arguments
+/// must denote pointer types.
bool
Sema::CastsAwayConstness(QualType SrcType, QualType DestType)
{
Modified: cfe/trunk/lib/Sema/SemaInherit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInherit.cpp?rev=58096&r1=58095&r2=58096&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInherit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInherit.cpp Fri Oct 24 11:17:19 2008
@@ -24,13 +24,15 @@
#include <set>
#include <string>
-namespace clang {
+using namespace clang;
/// isAmbiguous - Determines whether the set of paths provided is
/// ambiguous, i.e., there are two or more paths that refer to
/// different base class subobjects of the same type. BaseType must be
/// an unqualified, canonical class type.
bool BasePaths::isAmbiguous(QualType BaseType) {
+ assert(BaseType->isCanonical() && "Base type must be the canonical type");
+ assert(BaseType.getCVRQualifiers() == 0 && "Base type must be unqualified");
std::pair<bool, unsigned>& Subobjects = ClassSubobjects[BaseType];
return Subobjects.second + (Subobjects.first? 1 : 0) > 1;
}
@@ -141,8 +143,8 @@
/// if there is an error, and Range is the source range to highlight
/// if there is an error.
bool
-Sema::CheckDerivedToBaseConversion(SourceLocation Loc, SourceRange Range,
- QualType Derived, QualType Base) {
+Sema::CheckDerivedToBaseConversion(QualType Derived, QualType Base,
+ SourceLocation Loc, SourceRange Range) {
// 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
@@ -153,47 +155,43 @@
if (!DerivationOkay)
return true;
- if (Paths.isAmbiguous(Context.getCanonicalType(Base).getUnqualifiedType())) {
- // We know that the derived-to-base conversion is
- // ambiguous. Perform the derived-to-base search just one more
- // time to compute all of the possible paths so that we can print
- // them out. This is more expensive than any of the previous
- // derived-to-base checks we've done, but at this point we know
- // we'll be issuing a diagnostic so performance isn't as much of
- // an issue.
- Paths.clear();
- Paths.setRecordingPaths(true);
- bool StillOkay = IsDerivedFrom(Derived, Base, Paths);
- assert(StillOkay && "Can only be used with a derived-to-base conversion");
- if (!StillOkay)
- return true;
-
- // Build up a textual representation of the ambiguous paths, e.g.,
- // D -> B -> A, that will be used to illustrate the ambiguous
- // conversions in the diagnostic. We only print one of the paths
- // to each base class subobject.
- std::string PathDisplayStr;
- std::set<unsigned> DisplayedPaths;
- for (BasePaths::paths_iterator Path = Paths.begin();
- Path != Paths.end(); ++Path) {
- if (DisplayedPaths.insert(Path->back().SubobjectNumber).second) {
- // We haven't displayed a path to this particular base
- // class subobject yet.
- PathDisplayStr += "\n ";
- PathDisplayStr += Derived.getAsString();
- for (BasePath::const_iterator Element = Path->begin();
- Element != Path->end(); ++Element)
- PathDisplayStr += " -> " + Element->Base->getType().getAsString();
- }
- }
+ if (!Paths.isAmbiguous(Context.getCanonicalType(Base).getUnqualifiedType()))
+ return false;
- Diag(Loc, diag::err_ambiguous_derived_to_base_conv,
- Derived.getAsString(), Base.getAsString(), PathDisplayStr, Range);
+ // We know that the derived-to-base conversion is ambiguous, and
+ // we're going to produce a diagnostic. Perform the derived-to-base
+ // search just one more time to compute all of the possible paths so
+ // that we can print them out. This is more expensive than any of
+ // the previous derived-to-base checks we've done, but at this point
+ // performance isn't as much of an issue.
+ Paths.clear();
+ Paths.setRecordingPaths(true);
+ bool StillOkay = IsDerivedFrom(Derived, Base, Paths);
+ assert(StillOkay && "Can only be used with a derived-to-base conversion");
+ if (!StillOkay)
return true;
+
+ // Build up a textual representation of the ambiguous paths, e.g.,
+ // D -> B -> A, that will be used to illustrate the ambiguous
+ // conversions in the diagnostic. We only print one of the paths
+ // to each base class subobject.
+ std::string PathDisplayStr;
+ std::set<unsigned> DisplayedPaths;
+ for (BasePaths::paths_iterator Path = Paths.begin();
+ Path != Paths.end(); ++Path) {
+ if (DisplayedPaths.insert(Path->back().SubobjectNumber).second) {
+ // We haven't displayed a path to this particular base
+ // class subobject yet.
+ PathDisplayStr += "\n ";
+ PathDisplayStr += Derived.getAsString();
+ for (BasePath::const_iterator Element = Path->begin();
+ Element != Path->end(); ++Element)
+ PathDisplayStr += " -> " + Element->Base->getType().getAsString();
+ }
}
-
- return false;
+
+ Diag(Loc, diag::err_ambiguous_derived_to_base_conv,
+ Derived.getAsString(), Base.getAsString(), PathDisplayStr, Range);
+ return true;
}
-} // end namespace clang
-
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=58096&r1=58095&r2=58096&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri Oct 24 11:17:19 2008
@@ -721,9 +721,9 @@
ToPointeeType->isRecordType()) {
// We must have a derived-to-base conversion. Check an
// ambiguous or inaccessible conversion.
- return CheckDerivedToBaseConversion(From->getExprLoc(),
- From->getSourceRange(),
- FromPointeeType, ToPointeeType);
+ return CheckDerivedToBaseConversion(FromPointeeType, ToPointeeType,
+ From->getExprLoc(),
+ From->getSourceRange());
}
}
More information about the cfe-commits
mailing list