From b2d899e9ae8a48c4057a48664213948934b877fa Mon Sep 17 00:00:00 2001 From: Francois Pichet Date: Tue, 17 Apr 2012 12:35:05 +0000 Subject: [PATCH] Emulate a MSVC bug where the creation of pointer-to-member to protected member of base class is allowed but only from a static function. This fixes a regression when parsing MFC code with clang. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154924 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaAccess.cpp | 7 +++++++ test/Parser/MicrosoftExtensions.cpp | 27 ++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaAccess.cpp b/lib/Sema/SemaAccess.cpp index dea5e76d9e..024838d4d4 100644 --- a/lib/Sema/SemaAccess.cpp +++ b/lib/Sema/SemaAccess.cpp @@ -779,6 +779,13 @@ static AccessResult HasAccess(Sema &S, // that the naming class has to be derived from the effective // context. + // Emulate a MSVC bug where the creation of pointer-to-member + // to protected member of base class is allowed but only from + // a static function. + if (S.getLangOpts().MicrosoftMode && !EC.Functions.empty() && + EC.Functions.front()->getStorageClass() == SC_Static) + return AR_accessible; + // Despite the standard's confident wording, there is a case // where you can have an instance member that's neither in a // pointer-to-member expression nor in a member access: when diff --git a/test/Parser/MicrosoftExtensions.cpp b/test/Parser/MicrosoftExtensions.cpp index c6b3dfd691..3a1ffea453 100644 --- a/test/Parser/MicrosoftExtensions.cpp +++ b/test/Parser/MicrosoftExtensions.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions -fdelayed-template-parsing +// RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions -fms-compatibility -fdelayed-template-parsing /* Microsoft attribute tests */ [repeatable][source_annotation_attribute( Parameter|ReturnValue )] @@ -284,3 +284,28 @@ int main () { missing_template_keyword(); } + + + +namespace access_protected_PTM { + +class A { +protected: + void f(); // expected-note {{must name member using the type of the current context 'access_protected_PTM::B'}} +}; + +class B : public A{ +public: + void test_access(); + static void test_access_static(); +}; + +void B::test_access() { + &A::f; // expected-error {{'f' is a protected member of 'access_protected_PTM::A'}} +} + +void B::test_access_static() { + &A::f; +} + +} \ No newline at end of file -- 2.40.0