From: Eli Friedman Date: Mon, 12 Aug 2013 21:54:01 +0000 (+0000) Subject: Fix crash w/BlockDecl and invalid qualified decl. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a03c5eee51439b4d4d891284126831d10972e05c;p=clang Fix crash w/BlockDecl and invalid qualified decl. I'm not really satisfied with the ad-hoc nature of Sema::diagnoseQualifiedDeclaration, but I'm not sure how to fix it. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188208 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index fd1494445a..72a6fd9654 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -5100,6 +5100,8 @@ def err_invalid_declarator_global_scope : Error< "definition or redeclaration of %0 cannot name the global scope">; def err_invalid_declarator_in_function : Error< "definition or redeclaration of %0 not allowed inside a function">; +def err_invalid_declarator_in_block : Error< + "definition or redeclaration of %0 not allowed inside a block">; def err_not_tag_in_scope : Error< "no %select{struct|interface|union|class|enum}0 named %1 in %2">; def err_not_var_in_scope : Error< diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 077fc086d7..38de2b204a 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3998,7 +3998,7 @@ bool Sema::diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, DeclarationName Name, SourceLocation Loc) { DeclContext *Cur = CurContext; - while (isa(Cur)) + while (isa(Cur) || isa(Cur)) Cur = Cur->getParent(); // C++ [dcl.meaning]p1: @@ -4036,6 +4036,9 @@ bool Sema::diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, else if (isa(Cur)) Diag(Loc, diag::err_invalid_declarator_in_function) << Name << SS.getRange(); + else if (isa(Cur)) + Diag(Loc, diag::err_invalid_declarator_in_block) + << Name << SS.getRange(); else Diag(Loc, diag::err_invalid_declarator_scope) << Name << cast(Cur) << cast(DC) << SS.getRange(); diff --git a/test/SemaCXX/nested-name-spec.cpp b/test/SemaCXX/nested-name-spec.cpp index 40e7e07926..572e479824 100644 --- a/test/SemaCXX/nested-name-spec.cpp +++ b/test/SemaCXX/nested-name-spec.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++98 -verify %s +// RUN: %clang_cc1 -fsyntax-only -std=c++98 -verify -fblocks %s namespace A { struct C { static int cx; @@ -50,6 +50,7 @@ namespace B { void f1() { void A::Af(); // expected-error {{definition or redeclaration of 'Af' not allowed inside a function}} + void (^x)() = ^{ void A::Af(); }; // expected-error {{definition or redeclaration of 'Af' not allowed inside a block}} } void f2() {