From: Nico Weber Date: Wed, 20 Jun 2012 20:21:42 +0000 (+0000) Subject: Allow unqualified lookup of non-dependent member functions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4b554f4756cefdce6e0109e96d2f13d594b30b8c;p=clang Allow unqualified lookup of non-dependent member functions in microsoft mode. Fixes PR12701. The code for this was already in 2 of the 3 branches of a conditional and missing in the 3rd branch, so lift it above the conditional. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158842 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 57f1605fbe..adc8ea814e 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1466,14 +1466,14 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, // Give a code modification hint to insert 'this->'. // TODO: fixit for inserting 'Base::' in the other cases. // Actually quite difficult! + if (getLangOpts().MicrosoftMode) + diagnostic = diag::warn_found_via_dependent_bases_lookup; if (isInstance) { UnresolvedLookupExpr *ULE = cast( CallsUndergoingInstantiation.back()->getCallee()); CXXMethodDecl *DepMethod = cast_or_null( CurMethod->getInstantiatedFromMemberFunction()); if (DepMethod) { - if (getLangOpts().MicrosoftMode) - diagnostic = diag::warn_found_via_dependent_bases_lookup; Diag(R.getNameLoc(), diagnostic) << Name << FixItHint::CreateInsertion(R.getNameLoc(), "this->"); QualType DepThisType = DepMethod->getThisType(Context); @@ -1500,8 +1500,6 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, Diag(R.getNameLoc(), diagnostic) << Name; } } else { - if (getLangOpts().MicrosoftMode) - diagnostic = diag::warn_found_via_dependent_bases_lookup; Diag(R.getNameLoc(), diagnostic) << Name; } diff --git a/test/SemaTemplate/ms-lookup-template-base-classes.cpp b/test/SemaTemplate/ms-lookup-template-base-classes.cpp index 2c422dc7e3..8f80cb59e8 100644 --- a/test/SemaTemplate/ms-lookup-template-base-classes.cpp +++ b/test/SemaTemplate/ms-lookup-template-base-classes.cpp @@ -143,3 +143,32 @@ public: template class A; } + +namespace PR12701 { + +class A {}; +class B {}; + +template +class Base { + public: + bool base_fun(void* p) { return false; } // expected-note {{must qualify identifier to find this declaration in dependent base clas}} + operator T*() const { return 0; } +}; + +template +class Container : public Base { + public: + template + bool operator=(const Container& rhs) { + return base_fun(rhs); // expected-warning {{use of identifier 'base_fun' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}} + } +}; + +void f() { + Container text_provider; + Container text_provider2; + text_provider2 = text_provider; // expected-note {{in instantiation of function template specialization}} +} + +} // namespace PR12701