Author: Haojian Wu
Date: 2020-06-30T16:18:32+02:00
New Revision: d285f29317d6086e9ab941730f1ee5a468196a4e

URL: 
https://github.com/llvm/llvm-project/commit/d285f29317d6086e9ab941730f1ee5a468196a4e
DIFF: 
https://github.com/llvm/llvm-project/commit/d285f29317d6086e9ab941730f1ee5a468196a4e.diff

LOG: [AST][RecoveryExpr] Avoid spurious 'missing typename' diagnostic when the 
NNS contains errors.

Differential Revision: https://reviews.llvm.org/D82631

Added: 
    clang/test/SemaTemplate/nss-recovery.cpp

Modified: 
    clang/include/clang/AST/NestedNameSpecifier.h
    clang/lib/AST/NestedNameSpecifier.cpp
    clang/lib/Sema/SemaDecl.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/AST/NestedNameSpecifier.h 
b/clang/include/clang/AST/NestedNameSpecifier.h
index 47f5268c938b..540ac3df48fe 100644
--- a/clang/include/clang/AST/NestedNameSpecifier.h
+++ b/clang/include/clang/AST/NestedNameSpecifier.h
@@ -214,6 +214,9 @@ class NestedNameSpecifier : public llvm::FoldingSetNode {
   /// parameter pack (for C++11 variadic templates).
   bool containsUnexpandedParameterPack() const;
 
+  /// Whether this nested name specifier contains an error.
+  bool containsErrors() const;
+
   /// Print this nested name specifier to the given output stream. If
   /// `ResolveTemplateArguments` is true, we'll print actual types, e.g.
   /// `ns::SomeTemplate<int, MyClass>` instead of

diff  --git a/clang/lib/AST/NestedNameSpecifier.cpp 
b/clang/lib/AST/NestedNameSpecifier.cpp
index 87bf4e122ec8..08e8819a4d69 100644
--- a/clang/lib/AST/NestedNameSpecifier.cpp
+++ b/clang/lib/AST/NestedNameSpecifier.cpp
@@ -243,6 +243,10 @@ bool 
NestedNameSpecifier::containsUnexpandedParameterPack() const {
   return getDependence() & NestedNameSpecifierDependence::UnexpandedPack;
 }
 
+bool NestedNameSpecifier::containsErrors() const {
+  return getDependence() & NestedNameSpecifierDependence::Error;
+}
+
 /// Print this nested name specifier to the given output
 /// stream.
 void NestedNameSpecifier::print(raw_ostream &OS, const PrintingPolicy &Policy,

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 852f204ea7b1..f5e375134c29 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -750,7 +750,10 @@ void Sema::DiagnoseUnknownTypeName(IdentifierInfo *&II,
     Diag(IILoc, IsTemplateName ? diag::err_no_member_template
                                : diag::err_typename_nested_not_found)
         << II << DC << SS->getRange();
-  else if (isDependentScopeSpecifier(*SS)) {
+  else if (SS->isValid() && SS->getScopeRep()->containsErrors()) {
+    SuggestedType =
+        ActOnTypenameType(S, SourceLocation(), *SS, *II, IILoc).get();
+  } else if (isDependentScopeSpecifier(*SS)) {
     unsigned DiagID = diag::err_typename_missing;
     if (getLangOpts().MSVCCompat && isMicrosoftMissingTypename(SS, S))
       DiagID = diag::ext_typename_missing;

diff  --git a/clang/test/SemaTemplate/nss-recovery.cpp 
b/clang/test/SemaTemplate/nss-recovery.cpp
new file mode 100644
index 000000000000..08974cbbff11
--- /dev/null
+++ b/clang/test/SemaTemplate/nss-recovery.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// There should be no extra errors about missing 'typename' keywords.
+void f() {
+  decltype(undef())::Type T; // expected-error {{use of undeclared identifier}}
+}


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to