[cfe-commits] r145127 - in /cfe/trunk: lib/Sema/SemaExpr.cpp lib/Sema/SemaOverload.cpp test/SemaTemplate/ms-lookup-template-base-classes.cpp

Francois Pichet pichet2000 at gmail.com
Thu Nov 24 17:10:55 PST 2011


Author: fpichet
Date: Thu Nov 24 19:10:54 2011
New Revision: 145127

URL: http://llvm.org/viewvc/llvm-project?rev=145127&view=rev
Log:
In Microsoft mode, make "Unqualified lookup into dependent bases of class templates" works  inside a friend function definition at class scope.

Basically we have to look into the parent *lexical* DeclContext for friend functions at class scope. That's because calling GetParent() return the namespace or file DeclContext.

This fixes all remaining cases of "Unqualified lookup into dependent bases of class templates" when parsing MFC code with clang.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/test/SemaTemplate/ms-lookup-template-base-classes.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=145127&r1=145126&r2=145127&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Nov 24 19:10:54 2011
@@ -1511,8 +1511,8 @@
   // unqualified lookup.  This is useful when (for example) the
   // original lookup would not have found something because it was a
   // dependent name.
-  for (DeclContext *DC = SS.isEmpty() ? CurContext : 0;
-       DC; DC = DC->getParent()) {
+  DeclContext *DC = SS.isEmpty() ? CurContext : 0;
+  while (DC) {
     if (isa<CXXRecordDecl>(DC)) {
       LookupQualifiedName(R, DC);
 
@@ -1591,6 +1591,17 @@
 
       R.clear();
     }
+
+    // In Microsoft mode, if we are performing lookup from within a friend
+    // function definition declared at class scope then we must set
+    // DC to the lexical parent to be able to search into the parent
+    // class.
+    if (getLangOptions().MicrosoftMode && DC->isFunctionOrMethod() &&
+        cast<FunctionDecl>(DC)->getFriendObjectKind() &&
+        DC->getLexicalParent()->isRecord())
+      DC = DC->getLexicalParent();
+    else
+      DC = DC->getParent();
   }
 
   // We didn't find anything, so try to correct for a typo.

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=145127&r1=145126&r2=145127&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Nov 24 19:10:54 2011
@@ -8825,7 +8825,7 @@
     // to instantiation time to be able to search into type dependent base
     // classes.
     if (getLangOptions().MicrosoftMode && CurContext->isDependentContext() && 
-        (isa<CXXMethodDecl>(CurContext) || isa<CXXRecordDecl>(CurContext))) {
+        (isa<FunctionDecl>(CurContext) || isa<CXXRecordDecl>(CurContext))) {
       CallExpr *CE = new (Context) CallExpr(Context, Fn, Args, NumArgs,
                                           Context.DependentTy, VK_RValue,
                                           RParenLoc);

Modified: cfe/trunk/test/SemaTemplate/ms-lookup-template-base-classes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/ms-lookup-template-base-classes.cpp?rev=145127&r1=145126&r2=145127&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/ms-lookup-template-base-classes.cpp (original)
+++ cfe/trunk/test/SemaTemplate/ms-lookup-template-base-classes.cpp Thu Nov 24 19:10:54 2011
@@ -97,4 +97,29 @@
 	b.g2(); // expected-note {{required here}}
 }
 
-}
\ No newline at end of file
+}
+
+
+namespace lookup_dependent_base_class_friend {
+
+template <class T>
+class B {
+public:
+  static void g();  // expected-note {{must qualify identifier to find this declaration in dependent base class}} 
+};
+
+template <class T>
+class A : public B<T> {
+public:
+  friend void foo(A<T> p){
+    g(); // expected-warning {{use of identifier 'g' found via unqualified lookup into dependent bases of class templates is a Microsoft extension}}
+  }
+};
+
+int main2()
+{
+  A<int> a;
+  foo(a); // expected-note {{requested here}}
+}
+
+}





More information about the cfe-commits mailing list