Author: fpichet
Date: Tue Jul 26 20:05:24 2011
New Revision: 136203

URL: http://llvm.org/viewvc/llvm-project?rev=136203&view=rev
Log:
In Microsoft mode, if we are within a templated function and we can't resolve 
Identifier during BuildCXXNestedNameSpecifier, then extend the SS with 
Identifier. This will have  the effect of resolving Identifier during template 
instantiation.  The goal is to be able to resolve a function call whose 
nested-name-specifier is located inside a dependent base class.

class C {
public:
    static void foo2() {  }
};

template <class T> class A {
public:
   typedef C D;
};

template <class T> class B : public A<T> {
public:
  void foo() { D::foo2(); }
};

Note that this won't work if the NestedNameSpecifier refers to a type.
This fixes 1 error when parsing the MSVC 2010 standard headers file with clang.

Added:
    cfe/trunk/test/SemaTemplate/lookup-dependent-bases.cpp
Modified:
    cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp

Modified: cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp?rev=136203&r1=136202&r2=136203&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp Tue Jul 26 20:05:24 2011
@@ -615,6 +615,31 @@
     LookupName(Found, S);
   }
 
+  // In Microsoft mode, if we are within a templated function and we can't
+  // resolve Identifier, then extend the SS with Identifier. This will have 
+  // the effect of resolving Identifier during template instantiation. 
+  // The goal is to be able to resolve a function call whose
+  // nested-name-specifier is located inside a dependent base class.
+  // Example: 
+  //
+  // class C {
+  // public:
+  //    static void foo2() {  }
+  // };
+  // template <class T> class A { public: typedef C D; };
+  //
+  // template <class T> class B : public A<T> {
+  // public:
+  //   void foo() { D::foo2(); }
+  // };
+  if (getLangOptions().Microsoft) {
+    DeclContext *DC = LookupCtx ? LookupCtx : CurContext;
+    if (DC->isDependentContext() && DC->isFunctionOrMethod()) {
+      SS.Extend(Context, &Identifier, IdentifierLoc, CCLoc);
+      return false;
+    }
+  }
+
   unsigned DiagID;
   if (!Found.empty())
     DiagID = diag::err_expected_class_or_namespace;

Added: cfe/trunk/test/SemaTemplate/lookup-dependent-bases.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/lookup-dependent-bases.cpp?rev=136203&view=auto
==============================================================================
--- cfe/trunk/test/SemaTemplate/lookup-dependent-bases.cpp (added)
+++ cfe/trunk/test/SemaTemplate/lookup-dependent-bases.cpp Tue Jul 26 20:05:24 
2011
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s
+
+class C {
+public:
+   static void foo2() {  }
+};
+template <class T>
+class A {
+public:
+   typedef C D;
+};
+
+template <class T>
+class B : public A<T> {
+public:
+   void foo() {
+    D::foo2();
+   }
+};


_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to