From 7faf81ff1dc8f8dc724e928ba90ccbfad0fdc2bc Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 15 Nov 2013 23:00:02 +0000 Subject: [PATCH] PR17949: Fix crash if someone puts a namespace inside a class template. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194872 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticParseKinds.td | 4 ++-- include/clang/Parse/Parser.h | 2 +- lib/Parse/ParseDeclCXX.cpp | 10 +++++----- test/Parser/recovery.cpp | 5 +++++ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td index b895f3337a..4d0641de54 100644 --- a/include/clang/Basic/DiagnosticParseKinds.td +++ b/include/clang/Basic/DiagnosticParseKinds.td @@ -465,9 +465,9 @@ def err_expected_member_or_base_name : Error< def err_expected_lbrace_after_base_specifiers : Error< "expected '{' after base class list">; def err_missing_end_of_definition : Error< - "missing '}' at end of definition of %0">; + "missing '}' at end of definition of %q0">; def note_missing_end_of_definition_before : Note< - "still within definition of %0 here">; + "still within definition of %q0 here">; def ext_ellipsis_exception_spec : Extension< "exception specification of '...' is a Microsoft extension">, InGroup; diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index 1b26bba875..01dafba646 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -2084,7 +2084,7 @@ private: isCXX11AttributeSpecifier(bool Disambiguate = false, bool OuterMightBeMessageSend = false); - void DiagnoseUnexpectedNamespace(DeclContext *Context); + void DiagnoseUnexpectedNamespace(NamedDecl *Context); Decl *ParseNamespace(unsigned Context, SourceLocation &DeclEnd, SourceLocation InlineLoc = SourceLocation()); diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 3c534f7f27..0c3eab41f9 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -2627,7 +2627,7 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc, // If we see a namespace here, a close brace was missing somewhere. if (Tok.is(tok::kw_namespace)) { - DiagnoseUnexpectedNamespace(cast(TagDecl)); + DiagnoseUnexpectedNamespace(cast(TagDecl)); break; } @@ -2722,15 +2722,15 @@ void Parser::ParseCXXMemberSpecification(SourceLocation RecordLoc, ClassScope.Exit(); } -void Parser::DiagnoseUnexpectedNamespace(DeclContext *Ctx) { +void Parser::DiagnoseUnexpectedNamespace(NamedDecl *D) { assert(Tok.is(tok::kw_namespace)); // FIXME: Suggest where the close brace should have gone by looking // at indentation changes within the definition body. - Diag(cast(Ctx)->getLocation(), - diag::err_missing_end_of_definition) << Ctx; + Diag(D->getLocation(), + diag::err_missing_end_of_definition) << D; Diag(Tok.getLocation(), - diag::note_missing_end_of_definition_before) << Ctx; + diag::note_missing_end_of_definition_before) << D; // Push '};' onto the token stream to recover. PP.EnterToken(Tok); diff --git a/test/Parser/recovery.cpp b/test/Parser/recovery.cpp index 54e1b0adf2..0000f5c542 100644 --- a/test/Parser/recovery.cpp +++ b/test/Parser/recovery.cpp @@ -44,6 +44,11 @@ namespace MissingBrace { int k1 = S().h(); // expected-error {{no member named 'h' in 'MissingBrace::S'}} int k2 = S().f() + N::g(); + + template struct PR17949 { // expected-error {{missing '}' at end of definition of 'MissingBrace::PR17949'}} + + namespace X { // expected-note {{still within definition of 'MissingBrace::PR17949' here}} + } } namespace N { -- 2.50.1