r223090 - Perform correct lookup when '__super' is used in class with dependent base.
Nikola Smiljanic
popizdeh at gmail.com
Mon Dec 1 15:15:02 PST 2014
Author: nikola
Date: Mon Dec 1 17:15:01 2014
New Revision: 223090
URL: http://llvm.org/viewvc/llvm-project?rev=223090&view=rev
Log:
Perform correct lookup when '__super' is used in class with dependent base.
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExprMember.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/SemaCXX/MicrosoftSuper.cpp
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=223090&r1=223089&r2=223090&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Dec 1 17:15:01 2014
@@ -2646,6 +2646,8 @@ public:
bool AllowBuiltinCreation = false);
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
bool InUnqualifiedLookup = false);
+ bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
+ CXXScopeSpec &SS);
bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS,
bool AllowBuiltinCreation = false,
bool EnteringContext = false);
Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=223090&r1=223089&r2=223090&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Mon Dec 1 17:15:01 2014
@@ -625,7 +625,7 @@ static bool LookupMemberExprInRecord(Sem
}
// The record definition is complete, now look up the member.
- SemaRef.LookupQualifiedName(R, DC);
+ SemaRef.LookupQualifiedName(R, DC, SS);
if (!R.empty())
return false;
Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=223090&r1=223089&r2=223090&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Mon Dec 1 17:15:01 2014
@@ -1762,6 +1762,31 @@ bool Sema::LookupQualifiedName(LookupRes
return true;
}
+/// \brief Performs qualified name lookup or special type of lookup for
+/// "__super::" scope specifier.
+///
+/// This routine is a convenience overload meant to be called from contexts
+/// that need to perform a qualified name lookup with an optional C++ scope
+/// specifier that might require special kind of lookup.
+///
+/// \param R captures both the lookup criteria and any lookup results found.
+///
+/// \param LookupCtx The context in which qualified name lookup will
+/// search.
+///
+/// \param SS An optional C++ scope-specifier.
+///
+/// \returns true if lookup succeeded, false if it failed.
+bool Sema::LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
+ CXXScopeSpec &SS) {
+ auto *NNS = SS.getScopeRep();
+ if (NNS && NNS->getKind() == NestedNameSpecifier::Super)
+ return LookupInSuper(R, NNS->getAsRecordDecl());
+ else
+
+ return LookupQualifiedName(R, LookupCtx);
+}
+
/// @brief Performs name lookup for a name that was parsed in the
/// source code, and may contain a C++ scope specifier.
///
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=223090&r1=223089&r2=223090&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Mon Dec 1 17:15:01 2014
@@ -8004,11 +8004,7 @@ Sema::CheckTypenameType(ElaboratedTypeKe
DeclarationName Name(&II);
LookupResult Result(*this, Name, IILoc, LookupOrdinaryName);
- NestedNameSpecifier *NNS = SS.getScopeRep();
- if (NNS->getKind() == NestedNameSpecifier::Super)
- LookupInSuper(Result, NNS->getAsRecordDecl());
- else
- LookupQualifiedName(Result, Ctx);
+ LookupQualifiedName(Result, Ctx, SS);
unsigned DiagID = 0;
Decl *Referenced = nullptr;
switch (Result.getResultKind()) {
Modified: cfe/trunk/test/SemaCXX/MicrosoftSuper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftSuper.cpp?rev=223090&r1=223089&r2=223090&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/MicrosoftSuper.cpp (original)
+++ cfe/trunk/test/SemaCXX/MicrosoftSuper.cpp Mon Dec 1 17:15:01 2014
@@ -88,14 +88,14 @@ template <typename T>
struct BaseTemplate {
typedef int XXX;
- void foo() {}
+ int foo() { return 0; }
};
struct DerivedFromKnownSpecialization : BaseTemplate<int> {
__super::XXX a;
typedef __super::XXX b;
- void test() {
+ void foo() {
__super::XXX c;
typedef __super::XXX d;
@@ -111,14 +111,14 @@ struct DerivedFromDependentBase : BaseTe
__super::XXX c; // expected-error {{missing 'typename'}}
typedef __super::XXX d; // expected-error {{missing 'typename'}}
- void test() {
+ void foo() {
typename __super::XXX e;
typedef typename __super::XXX f;
__super::XXX g; // expected-error {{missing 'typename'}}
typedef __super::XXX h; // expected-error {{missing 'typename'}}
- __super::foo();
+ int x = __super::foo();
}
};
@@ -130,7 +130,7 @@ struct DerivedFromTemplateParameter : T
__super::XXX c; // expected-error {{missing 'typename'}}
typedef __super::XXX d; // expected-error {{missing 'typename'}}
- void test() {
+ void foo() {
typename __super::XXX e;
typedef typename __super::XXX f;
@@ -143,7 +143,7 @@ struct DerivedFromTemplateParameter : T
void instantiate() {
DerivedFromDependentBase<int> d;
- d.test();
+ d.foo();
DerivedFromTemplateParameter<Base1> t;
- t.test();
+ t.foo();
}
More information about the cfe-commits
mailing list