aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaOverload.cpp
diff options
context:
space:
mode:
authorSebastian Redl <sebastian.redl@getdesigned.at>2009-01-28 18:33:18 +0000
committerSebastian Redl <sebastian.redl@getdesigned.at>2009-01-28 18:33:18 +0000
commit21593acb933324b439bc68b68e7cc7d1c3e3484d (patch)
tree6feee8a9f735cae4af555e7a7395a67e696d226d /lib/Sema/SemaOverload.cpp
parent66973121788ca645fe3d4a66179b9cfb6f2bce08 (diff)
Implement pointer to member handling in static_cast.
Fix a stupid mistake in UnwrapSimilarPointers that made any two member pointers compatible as long as the pointee was the same. Make a few style corrections as suggested by Chris. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63215 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaOverload.cpp')
-rw-r--r--lib/Sema/SemaOverload.cpp85
1 files changed, 42 insertions, 43 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index b2ae90b4b8..0f9f0cf9c6 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -1087,51 +1087,50 @@ bool Sema::IsMemberPointerConversion(Expr *From, QualType FromType,
/// otherwise.
bool Sema::CheckMemberPointerConversion(Expr *From, QualType ToType) {
QualType FromType = From->getType();
+ const MemberPointerType *FromPtrType = FromType->getAsMemberPointerType();
+ if (!FromPtrType)
+ return false;
- if (const MemberPointerType *FromPtrType =
- FromType->getAsMemberPointerType()) {
- if (const MemberPointerType *ToPtrType =
- ToType->getAsMemberPointerType()) {
- QualType FromClass = QualType(FromPtrType->getClass(), 0);
- QualType ToClass = QualType(ToPtrType->getClass(), 0);
-
- // FIXME: What about dependent types?
- assert(FromClass->isRecordType() && "Pointer into non-class.");
- assert(ToClass->isRecordType() && "Pointer into non-class.");
-
- BasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/false,
- /*DetectVirtual=*/true);
- bool DerivationOkay = IsDerivedFrom(ToClass, FromClass, Paths);
- assert(DerivationOkay &&
- "Should not have been called if derivation isn't OK.");
- if (!DerivationOkay)
- return true;
-
- if (Paths.isAmbiguous(Context.getCanonicalType(FromClass).
- getUnqualifiedType())) {
- // Derivation is ambiguous. Redo the check to find the exact paths.
- Paths.clear();
- Paths.setRecordingPaths(true);
- bool StillOkay = IsDerivedFrom(ToClass, FromClass, Paths);
- assert(StillOkay && "Derivation changed due to quantum fluctuation.");
- if (!StillOkay)
- return true;
-
- std::string PathDisplayStr = getAmbiguousPathsDisplayString(Paths);
- Diag(From->getExprLoc(),
- diag::err_ambiguous_base_to_derived_memptr_conv)
- << FromClass << ToClass << PathDisplayStr << From->getSourceRange();
- return true;
- }
+ const MemberPointerType *ToPtrType = ToType->getAsMemberPointerType();
+ assert(ToPtrType && "No member pointer cast has a target type "
+ "that is not a member pointer.");
+
+ QualType FromClass = QualType(FromPtrType->getClass(), 0);
+ QualType ToClass = QualType(ToPtrType->getClass(), 0);
+
+ // FIXME: What about dependent types?
+ assert(FromClass->isRecordType() && "Pointer into non-class.");
+ assert(ToClass->isRecordType() && "Pointer into non-class.");
+
+ BasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/false,
+ /*DetectVirtual=*/true);
+ bool DerivationOkay = IsDerivedFrom(ToClass, FromClass, Paths);
+ assert(DerivationOkay &&
+ "Should not have been called if derivation isn't OK.");
+ (void)DerivationOkay;
+
+ if (Paths.isAmbiguous(Context.getCanonicalType(FromClass).
+ getUnqualifiedType())) {
+ // Derivation is ambiguous. Redo the check to find the exact paths.
+ Paths.clear();
+ Paths.setRecordingPaths(true);
+ bool StillOkay = IsDerivedFrom(ToClass, FromClass, Paths);
+ assert(StillOkay && "Derivation changed due to quantum fluctuation.");
+ (void)StillOkay;
+
+ std::string PathDisplayStr = getAmbiguousPathsDisplayString(Paths);
+ Diag(From->getExprLoc(), diag::err_ambiguous_memptr_conv)
+ << 0 << FromClass << ToClass << PathDisplayStr << From->getSourceRange();
+ return true;
+ }
- if (const CXXRecordType *VBase = Paths.getDetectedVirtual()) {
- Diag(From->getExprLoc(), diag::err_memptr_conv_via_virtual)
- << FromClass << ToClass << QualType(VBase, 0)
- << From->getSourceRange();
- return true;
- }
- }
+ if (const CXXRecordType *VBase = Paths.getDetectedVirtual()) {
+ Diag(From->getExprLoc(), diag::err_memptr_conv_via_virtual)
+ << FromClass << ToClass << QualType(VBase, 0)
+ << From->getSourceRange();
+ return true;
}
+
return false;
}
@@ -1148,7 +1147,7 @@ Sema::IsQualificationConversion(QualType FromType, QualType ToType)
// qualification conversion.
if (FromType == ToType)
return false;
-
+
// (C++ 4.4p4):
// A conversion can add cv-qualifiers at levels other than the first
// in multi-level pointers, subject to the following rules: [...]