From c20063a2953bc57a6daf31f029010aa992191ae2 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Wed, 17 Dec 2014 19:34:15 +0000 Subject: [PATCH] Don't build invalid AST nodes during recovery A DependentScopeDeclRefExpr should always have a nested name specifier. During template instantiation, if we found that the named context was incomplete, we would previously build a DependentScopeDeclRefExpr with an empty qualifier. This error recovery path has been asserting for some time. The other error codepaths use ExprError, so we can do the same. Fixes PR21864. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224451 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplate.cpp | 2 +- .../instantiate-dependent-nested-name.cpp | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 07e3137f84..f2e951e574 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -2877,7 +2877,7 @@ Sema::BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, if (!(DC = computeDeclContext(SS, false)) || DC->isDependentContext() || RequireCompleteDeclContext(SS, DC)) - return BuildDependentDeclRefExpr(SS, TemplateKWLoc, NameInfo, TemplateArgs); + return ExprError(); bool MemberOfUnknownSpecialization; LookupResult R(*this, NameInfo, LookupOrdinaryName); diff --git a/test/SemaTemplate/instantiate-dependent-nested-name.cpp b/test/SemaTemplate/instantiate-dependent-nested-name.cpp index 06a1ed4119..cb2c946ede 100644 --- a/test/SemaTemplate/instantiate-dependent-nested-name.cpp +++ b/test/SemaTemplate/instantiate-dependent-nested-name.cpp @@ -1,8 +1,19 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -// expected-no-diagnostics + // PR4382 template struct X { static const T A = 1; }; template::A> struct Y { typedef T A; }; template struct Z { typedef typename Y::A A; }; extern int x; extern Z::A x; + +namespace pr21964 { +struct H; +template struct T { + struct A; // expected-note {{member is declared here}} + static void B() { + A::template N; // expected-error {{implicit instantiation of undefined member 'pr21964::T::A'}} + } +}; +template struct T; // expected-note {{requested here}} +} -- 2.40.0