diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2013-08-12 21:54:01 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2013-08-12 21:54:01 +0000 |
commit | e2358c1debe988a9ff262cb267c791c93ee04a4a (patch) | |
tree | 4581450a8c22528a7a9d24a26350ca6f48bb53ad | |
parent | 48a317663fab26e9fd2b36f0379b348737b7be3b (diff) | |
download | bcm5719-llvm-e2358c1debe988a9ff262cb267c791c93ee04a4a.tar.gz bcm5719-llvm-e2358c1debe988a9ff262cb267c791c93ee04a4a.zip |
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 <rdar://problem/14639501>.
llvm-svn: 188208
-rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 5 | ||||
-rw-r--r-- | clang/test/SemaCXX/nested-name-spec.cpp | 3 |
3 files changed, 8 insertions, 2 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index fd1494445af..72a6fd9654d 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/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/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 077fc086d7c..38de2b204a8 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -3998,7 +3998,7 @@ bool Sema::diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, DeclarationName Name, SourceLocation Loc) { DeclContext *Cur = CurContext; - while (isa<LinkageSpecDecl>(Cur)) + while (isa<LinkageSpecDecl>(Cur) || isa<CapturedDecl>(Cur)) Cur = Cur->getParent(); // C++ [dcl.meaning]p1: @@ -4036,6 +4036,9 @@ bool Sema::diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, else if (isa<FunctionDecl>(Cur)) Diag(Loc, diag::err_invalid_declarator_in_function) << Name << SS.getRange(); + else if (isa<BlockDecl>(Cur)) + Diag(Loc, diag::err_invalid_declarator_in_block) + << Name << SS.getRange(); else Diag(Loc, diag::err_invalid_declarator_scope) << Name << cast<NamedDecl>(Cur) << cast<NamedDecl>(DC) << SS.getRange(); diff --git a/clang/test/SemaCXX/nested-name-spec.cpp b/clang/test/SemaCXX/nested-name-spec.cpp index 40e7e079261..572e4798244 100644 --- a/clang/test/SemaCXX/nested-name-spec.cpp +++ b/clang/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() { |