From: Nikola Smiljanic Date: Sat, 4 Oct 2014 10:17:57 +0000 (+0000) Subject: -ms-extensions: Allow __super in return stements. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=107c30e2395b1e3bd1584b134f5b9ef7bc352895;p=clang -ms-extensions: Allow __super in return stements. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219050 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 769c18edd9..ddc997d64d 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -2616,7 +2616,7 @@ public: ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc, RedeclarationKind Redecl = NotForRedeclaration); - void LookupInSuper(LookupResult &R, CXXRecordDecl *Class); + bool LookupInSuper(LookupResult &R, CXXRecordDecl *Class); void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, QualType T1, QualType T2, diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index c3c436d8e3..22a7e732c5 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -702,11 +702,7 @@ Sema::NameClassification Sema::ClassifyName(Scope *S, } LookupResult Result(*this, Name, NameLoc, LookupOrdinaryName); - NestedNameSpecifier *NNS = SS.getScopeRep(); - if (NNS && NNS->getKind() == NestedNameSpecifier::Super) - LookupInSuper(Result, NNS->getAsRecordDecl()); - else - LookupParsedName(Result, S, &SS, !CurMethod); + LookupParsedName(Result, S, &SS, !CurMethod); // For unqualified lookup in a class template in MSVC mode, look into // dependent base classes where the primary class template is known. diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 76e0ba1bcd..639e651121 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -1782,7 +1782,8 @@ bool Sema::LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, /// contexts that receive a name and an optional C++ scope specifier /// (e.g., "N::M::x"). It will then perform either qualified or /// unqualified name lookup (with LookupQualifiedName or LookupName, -/// respectively) on the given name and return those results. +/// respectively) on the given name and return those results. It will +/// perform a special type of lookup for "__super::" scope specifier. /// /// @param S The scope from which unqualified name lookup will /// begin. @@ -1802,6 +1803,10 @@ bool Sema::LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, } if (SS && SS->isSet()) { + NestedNameSpecifier *NNS = SS->getScopeRep(); + if (NNS->getKind() == NestedNameSpecifier::Super) + return LookupInSuper(R, NNS->getAsRecordDecl()); + if (DeclContext *DC = computeDeclContext(*SS, EnteringContext)) { // We have resolved the scope specifier to a particular declaration // contex, and will perform name lookup in that context. @@ -1831,7 +1836,9 @@ bool Sema::LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, /// /// \param Class The context in which qualified name lookup will /// search. Name lookup will search in all base classes merging the results. -void Sema::LookupInSuper(LookupResult &R, CXXRecordDecl *Class) { +/// +/// @returns True if any decls were found (but possibly ambiguous) +bool Sema::LookupInSuper(LookupResult &R, CXXRecordDecl *Class) { for (const auto &BaseSpec : Class->bases()) { CXXRecordDecl *RD = cast( BaseSpec.getType()->castAs()->getDecl()); @@ -1843,6 +1850,8 @@ void Sema::LookupInSuper(LookupResult &R, CXXRecordDecl *Class) { } R.resolveKind(); + + return !R.empty(); } /// \brief Produce a diagnostic describing the ambiguity that resulted diff --git a/test/SemaCXX/MicrosoftSuper.cpp b/test/SemaCXX/MicrosoftSuper.cpp index 1bf97ac5e0..13138ca000 100644 --- a/test/SemaCXX/MicrosoftSuper.cpp +++ b/test/SemaCXX/MicrosoftSuper.cpp @@ -29,12 +29,14 @@ struct Derived : Base1 { X = sizeof(__super::XXX) }; - void foo(int i) { - __super::foo(i); + void foo() { + __super::foo(1); - if (i == 0) { - __super::foo(i); + if (true) { + __super::foo(1); } + + return __super::foo(1); } static void bar() {