Wrong lookup performed for __super

Nikola Smiljanic popizdeh at gmail.com
Tue Nov 11 23:00:00 PST 2014


Something like this?

On Tue, Nov 11, 2014 at 6:47 AM, Reid Kleckner <rnk at google.com> wrote:

> I see lots of calls to LookupQualifiedName and only a few of them check if
> they should call LookupInSuper.
>
> Many users of LookupQualifiedName are looking up thinks like
> SomeClass::operator=, so they don't have a CXXScopeSpec. Maybe we should
> add a CXXScopeSpec overload to LookupQualifiedName to make it easier for
> callers to do the right thing?
>
> On Fri, Nov 7, 2014 at 3:31 AM, Nikola Smiljanic <popizdeh at gmail.com>
> wrote:
>
>> Ping
>>
>> On Fri, Oct 24, 2014 at 11:35 AM, Nikola Smiljanic <popizdeh at gmail.com>
>> wrote:
>>
>>> It seems that there's one more place where we need to call
>>> LookupInSuper. I've modified the relevant tests to catch this by having
>>> different signature for the method and making sure the right one is called.
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141112/fa8c0a43/attachment.html>
-------------- next part --------------
diff --git include/clang/Sema/Sema.h include/clang/Sema/Sema.h
index 2ecaf53..461784a 100644
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -2645,6 +2645,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);
diff --git lib/Sema/SemaExprMember.cpp lib/Sema/SemaExprMember.cpp
index 0d7f3c6..b8ed376 100644
--- lib/Sema/SemaExprMember.cpp
+++ lib/Sema/SemaExprMember.cpp
@@ -649,7 +649,7 @@ static bool LookupMemberExprInRecord(
   }
 
   // The record definition is complete, now look up the member.
-  SemaRef.LookupQualifiedName(R, DC);
+  SemaRef.LookupQualifiedName(R, DC, SS);
 
   if (!R.empty())
     return false;
diff --git lib/Sema/SemaLookup.cpp lib/Sema/SemaLookup.cpp
index eab819e..883d69c 100644
--- lib/Sema/SemaLookup.cpp
+++ lib/Sema/SemaLookup.cpp
@@ -1762,6 +1762,31 @@ bool Sema::LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx,
   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.
 ///
diff --git lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplate.cpp
index 57d1ab8..aeb581e 100644
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -7900,11 +7900,7 @@ Sema::CheckTypenameType(ElaboratedTypeKeyword Keyword,
 
   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()) {
diff --git test/SemaCXX/MicrosoftSuper.cpp test/SemaCXX/MicrosoftSuper.cpp
index 13138ca..cb21656 100644
--- test/SemaCXX/MicrosoftSuper.cpp
+++ test/SemaCXX/MicrosoftSuper.cpp
@@ -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 : BaseTemplate<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;
 
     __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