summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-01-16 12:02:55 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-01-16 12:02:55 +0000
commitf5b93794b7115ec019882b71936202467608c1b6 (patch)
treec308b336b35f358df4bee1b365c239cd086b4531
parent780d85a8ef9aa81bb81d8b68715c30483c4f78aa (diff)
downloadbcm5719-llvm-f5b93794b7115ec019882b71936202467608c1b6.tar.gz
bcm5719-llvm-f5b93794b7115ec019882b71936202467608c1b6.zip
Sema: Fix crash during member pointer conversion involving incomplete classes
We would attempt to determine the inheritance relationship between classes 'A' and 'B' during static_cast if we tried to convert from 'int A::*' to 'int B::*'. However, the question "does A derive from B" is not meaningful when 'A' isn't defined. Handle this case by requiring that 'A' be defined. This fixes PR18506. llvm-svn: 199374
-rw-r--r--clang/lib/Sema/SemaCast.cpp3
-rw-r--r--clang/test/SemaCXX/static-cast.cpp3
2 files changed, 5 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index ef229cf838b..63cb15db529 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -1346,7 +1346,8 @@ TryStaticMemberPointerUpcast(Sema &Self, ExprResult &SrcExpr, QualType SrcType,
QualType DestClass(DestMemPtr->getClass(), 0);
CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true,
/*DetectVirtual=*/true);
- if (!Self.IsDerivedFrom(SrcClass, DestClass, Paths)) {
+ if (Self.RequireCompleteType(OpRange.getBegin(), SrcClass, 0) ||
+ !Self.IsDerivedFrom(SrcClass, DestClass, Paths)) {
return TC_NotApplicable;
}
diff --git a/clang/test/SemaCXX/static-cast.cpp b/clang/test/SemaCXX/static-cast.cpp
index 03ee160ca3e..06fd8636e5d 100644
--- a/clang/test/SemaCXX/static-cast.cpp
+++ b/clang/test/SemaCXX/static-cast.cpp
@@ -9,6 +9,8 @@ struct F : public C1 {}; // Single path to B with virtual.
struct G1 : public B {};
struct G2 : public B {};
struct H : public G1, public G2 {}; // Ambiguous path to B.
+struct I; // Incomplete.
+struct J; // Incomplete.
enum Enum { En1, En2 };
enum Onom { On1, On2 };
@@ -131,6 +133,7 @@ void t_529_9()
// Bad code below
(void)static_cast<int A::*>((int H::*)0); // expected-error {{ambiguous conversion from pointer to member of derived class 'H' to pointer to member of base class 'A':}}
(void)static_cast<int A::*>((int F::*)0); // expected-error {{conversion from pointer to member of class 'F' to pointer to member of class 'A' via virtual base 'B' is not allowed}}
+ (void)static_cast<int I::*>((int J::*)0); // expected-error {{static_cast from 'int J::*' to 'int I::*' is not allowed}}
}
// PR 5261 - static_cast should instantiate template if possible
OpenPOWER on IntegriCloud