From: Eli Friedman Date: Fri, 23 Jul 2010 19:25:41 +0000 (+0000) Subject: Fix for PR7694: make sure to pass in a RecordType to CheckBaseClassAccess; X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0fab8cd9bd9093ce16b6ce64a152d861ba408652;p=clang Fix for PR7694: make sure to pass in a RecordType to CheckBaseClassAccess; fixes crashes on both valid and invalid code. The diagnostic here could potentially be improved, but it's good enough as-is. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109257 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaCXXCast.cpp b/lib/Sema/SemaCXXCast.cpp index b8e27e7b72..787bd00ac8 100644 --- a/lib/Sema/SemaCXXCast.cpp +++ b/lib/Sema/SemaCXXCast.cpp @@ -900,7 +900,7 @@ TryStaticMemberPointerUpcast(Sema &Self, Expr *&SrcExpr, QualType SrcType, } if (!CStyle && Self.CheckBaseClassAccess(OpRange.getBegin(), - DestType, SrcType, + DestClass, SrcClass, Paths.front(), diag::err_upcast_to_inaccessible_base)) { msg = 0; diff --git a/test/SemaCXX/access-member-pointer.cpp b/test/SemaCXX/access-member-pointer.cpp new file mode 100644 index 0000000000..676eb10dcd --- /dev/null +++ b/test/SemaCXX/access-member-pointer.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// PR7694 + +class A { }; +class B : private A { public: void foo(); }; // expected-note {{declared private here}} +void B::foo() { + (void)static_cast(&B::foo); +} +void bar() { + (void)static_cast(&B::foo); // expected-error {{cannot cast 'B' to its private base class 'A'}} +}