Implement the notions of the "current instantiation" and "unknown
specialization" within a C++ template, and permit name lookup into the
current instantiation. For example, given:

  template<typename T, typename U>
  struct X {
    typedef T type;

    X* x1;  // current instantiation
    X<T, U> *x2; // current instantiation
    X<U, T> *x3; // not current instantiation
    ::X<type, U> *x4; // current instantiation
    X<typename X<type, U>::type, U>: *x5; // current instantiation
  };



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71471 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index d9e883f..c778ca6 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -64,16 +64,15 @@
   //   qualified-id denotes a type, forming an
   //   elaborated-type-specifier (7.1.5.3).
   //
-  // We therefore do not perform any name lookup up SS is a dependent
-  // scope name. FIXME: we will need to perform a special kind of
-  // lookup if the scope specifier names a member of the current
-  // instantiation.
-  if (SS && isDependentScopeSpecifier(*SS))
+  // We therefore do not perform any name lookup if the result would
+  // refer to a member of an unknown specialization.
+  if (SS && isUnknownSpecialization(*SS))
     return 0;
 
+  LookupResult Result 
+    = LookupParsedName(S, SS, &II, LookupOrdinaryName, false, false);
+
   NamedDecl *IIDecl = 0;
-  LookupResult Result = LookupParsedName(S, SS, &II, LookupOrdinaryName, 
-                                         false, false);
   switch (Result.getKind()) {
   case LookupResult::NotFound:
   case LookupResult::FoundOverloaded:
@@ -3402,7 +3401,7 @@
     }
   } else if (TK == TK_Reference && SS.isEmpty() && Name &&
              (Kind != TagDecl::TK_enum || !getLangOptions().CPlusPlus)) {
-    // C.scope.pdecl]p5:
+    // C++ [basic.scope.pdecl]p5:
     //   -- for an elaborated-type-specifier of the form 
     //
     //          class-key identifier