If we see a declaration which is either missing a type or has a malformed type,
and the thing we have has a scope specifier, and we're in a context that doesn't
allow declaring a qualified name, then the error is a malformed type, not a
missing type.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156856 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index dcc96cb..36e3013 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -1707,7 +1707,10 @@
     }
   }
 
-  if (DSC != DSC_type_specifier && DSC != DSC_trailing) {
+  // Determine whether this identifier could plausibly be the name of something
+  // being declared (with a missign type).
+  if (DSC != DSC_type_specifier && DSC != DSC_trailing &&
+      (!SS || DSC == DSC_top_level || DSC == DSC_class)) {
     // Look ahead to the next token to try to figure out what this declaration
     // was supposed to be.
     switch (NextToken().getKind()) {
diff --git a/test/SemaCXX/unknown-type-name.cpp b/test/SemaCXX/unknown-type-name.cpp
index 5f8d8ca..7912fbe 100644
--- a/test/SemaCXX/unknown-type-name.cpp
+++ b/test/SemaCXX/unknown-type-name.cpp
@@ -20,6 +20,8 @@
   typedef T type;
   
   type f();
+
+  type g();
 };
 
 template<typename T>
@@ -27,3 +29,14 @@
 
 template<typename T>
 A<T>::type A<T>::f() { return type(); } // expected-error{{missing 'typename'}}
+
+template<typename T>
+void f(int, T::type) { } // expected-error{{missing 'typename'}}
+
+template<typename T>
+void f(int, T::type, int) { } // expected-error{{missing 'typename'}}
+
+// FIXME: We know which type specifier should have been specified here. Provide
+//        a fix-it to add 'typename A<T>::type'
+template<typename T>
+A<T>::g() { } // expected-error{{requires a type specifier}}