[cfe-commits] r125532 - in /cfe/trunk: lib/Sema/SemaCXXCast.cpp test/CXX/class.access/class.friend/p1.cpp
John McCall
rjmccall at apple.com
Mon Feb 14 15:21:34 PST 2011
Author: rjmccall
Date: Mon Feb 14 17:21:33 2011
New Revision: 125532
URL: http://llvm.org/viewvc/llvm-project?rev=125532&view=rev
Log:
Don't crash on hierarchy static_casts which appear in variable initializers.
PR9221.
Modified:
cfe/trunk/lib/Sema/SemaCXXCast.cpp
cfe/trunk/test/CXX/class.access/class.friend/p1.cpp
Modified: cfe/trunk/lib/Sema/SemaCXXCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXCast.cpp?rev=125532&r1=125531&r2=125532&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Mon Feb 14 17:21:33 2011
@@ -981,12 +981,20 @@
return TC_Failed;
}
- if (!CStyle && Self.CheckBaseClassAccess(OpRange.getBegin(),
- SrcType, DestType,
- Paths.front(),
+ if (!CStyle) {
+ switch (Self.CheckBaseClassAccess(OpRange.getBegin(),
+ SrcType, DestType,
+ Paths.front(),
diag::err_downcast_from_inaccessible_base)) {
- msg = 0;
- return TC_Failed;
+ case Sema::AR_accessible:
+ case Sema::AR_delayed: // be optimistic
+ case Sema::AR_dependent: // be optimistic
+ break;
+
+ case Sema::AR_inaccessible:
+ msg = 0;
+ return TC_Failed;
+ }
}
Self.BuildBasePathArray(Paths, BasePath);
@@ -1065,12 +1073,22 @@
return TC_Failed;
}
- if (!CStyle && Self.CheckBaseClassAccess(OpRange.getBegin(),
- DestClass, SrcClass,
- Paths.front(),
- diag::err_upcast_to_inaccessible_base)) {
- msg = 0;
- return TC_Failed;
+ if (!CStyle) {
+ switch (Self.CheckBaseClassAccess(OpRange.getBegin(),
+ DestClass, SrcClass,
+ Paths.front(),
+ diag::err_upcast_to_inaccessible_base)) {
+ case Sema::AR_accessible:
+ case Sema::AR_delayed:
+ case Sema::AR_dependent:
+ // Optimistically assume that the delayed and dependent cases
+ // will work out.
+ break;
+
+ case Sema::AR_inaccessible:
+ msg = 0;
+ return TC_Failed;
+ }
}
if (WasOverloadedFunction) {
Modified: cfe/trunk/test/CXX/class.access/class.friend/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class.access/class.friend/p1.cpp?rev=125532&r1=125531&r2=125532&view=diff
==============================================================================
--- cfe/trunk/test/CXX/class.access/class.friend/p1.cpp (original)
+++ cfe/trunk/test/CXX/class.access/class.friend/p1.cpp Mon Feb 14 17:21:33 2011
@@ -326,3 +326,18 @@
void A::test2(B::private_type x) {} // expected-error {{'private_type' is a private member of 'test11::B'}}
void A::test3(int x = B::private_type()) {} // expected-error {{'private_type' is a private member of 'test11::B'}}
}
+
+
+// PR9221
+namespace test12 {
+ struct A {
+ void foo();
+ };
+ class B : private A {
+ friend void A::foo();
+ void *mem;
+ };
+ void A::foo() {
+ void *var = static_cast<B*>(this)->mem;
+ }
+}
More information about the cfe-commits
mailing list