Improve diagnostics and recovery when the nested-name-specifier of a
qualified name does not actually refer into a class/class
template/class template partial specialization. 

Improve printing of nested-name-specifiers to eliminate redudant
qualifiers. Also, make it possible to output a nested-name-specifier
through a DiagnosticBuilder, although there are relatively few places
that will use this leeway.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80056 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index 5425c4f..24c5e09 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -79,8 +79,7 @@
     else
       assert(ModLen == 0 && ArgLen == 0 &&
              "Invalid modifier for DeclarationName argument");
-  } else {
-    assert(Kind == Diagnostic::ak_nameddecl);
+  } else if (Kind == Diagnostic::ak_nameddecl) {
     if (ModLen == 1 && Modifier[0] == 'q' && ArgLen == 0)
       S = reinterpret_cast<NamedDecl*>(Val)->getQualifiedNameAsString();
     else { 
@@ -88,6 +87,11 @@
            "Invalid modifier for NamedDecl* argument");
       S = reinterpret_cast<NamedDecl*>(Val)->getNameAsString();
     }
+  } else {
+    llvm::raw_string_ostream OS(S);
+    assert(Kind == Diagnostic::ak_nestednamespec);
+    reinterpret_cast<NestedNameSpecifier*> (Val)->print(OS, 
+                                                        Context.PrintingPolicy);
   }
   
   Output.push_back('\'');