From 8a9013d24864272cf5b18c908a267bd7a2bda4c4 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Thu, 14 Apr 2011 17:21:19 +0000 Subject: [PATCH] Parse an '@' in an Objective-C++ class member specification, diagnosing it as an error rather than looping infinitely. Also, explicitly disallow @defs in Objective-C++. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129521 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticParseKinds.td | 7 +++++-- lib/Parse/ParseDeclCXX.cpp | 11 +++++++++++ test/Parser/objcxx-at.mm | 15 +++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 test/Parser/objcxx-at.mm diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td index 82c73d0194..273d6cc088 100644 --- a/include/clang/Basic/DiagnosticParseKinds.td +++ b/include/clang/Basic/DiagnosticParseKinds.td @@ -120,6 +120,9 @@ def err_function_declared_typedef : Error< def err_iboutletcollection_builtintype : Error< "type argument of iboutletcollection attribute cannot be a builtin type">; +def err_at_defs_cxx : Error<"@defs is not supported in Objective-C++">; +def err_at_in_class : Error<"unexpected '@' in member specification">; + def err_expected_fn_body : Error< "expected function body after function declarator">; def err_expected_method_body : Error<"expected method body">; @@ -370,8 +373,8 @@ def err_enum_template : Error<"enumeration cannot be a template">; def err_missing_dependent_template_keyword : Error< "use 'template' keyword to treat '%0' as a dependent template name">; -def war_missing_dependent_template_keyword : ExtWarn< - "use 'template' keyword to treat '%0' as a dependent template name">; +def war_missing_dependent_template_keyword : ExtWarn< + "use 'template' keyword to treat '%0' as a dependent template name">; def warn_static_inline_explicit_inst_ignored : Warning< "ignoring '%select{static|inline}0' keyword on explicit template " diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index dac40d8713..9c0730dce9 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -1374,6 +1374,17 @@ bool Parser::isCXX0XFinalKeyword() const { void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS, const ParsedTemplateInfo &TemplateInfo, ParsingDeclRAIIObject *TemplateDiags) { + if (Tok.is(tok::at)) { + if (getLang().ObjC1 && NextToken().isObjCAtKeyword(tok::objc_defs)) + Diag(Tok, diag::err_at_defs_cxx); + else + Diag(Tok, diag::err_at_in_class); + + ConsumeToken(); + SkipUntil(tok::r_brace); + return; + } + // Access declarations. if (!TemplateInfo.Kind && (Tok.is(tok::identifier) || Tok.is(tok::coloncolon)) && diff --git a/test/Parser/objcxx-at.mm b/test/Parser/objcxx-at.mm new file mode 100644 index 0000000000..37aee4dd6a --- /dev/null +++ b/test/Parser/objcxx-at.mm @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +@interface B { + int i; +} +@end + +struct Z { + @defs(B); // expected-error{{@defs is not supported in Objective-C++}} +}; + +struct Y { // expected-note{{to match this '{'}} + struct X { } // expected-error{{expected ';' after struct}} + @interface A // expected-error{{unexpected '@' in member specification}} +} // expected-error{{expected '}'}} expected-error{{expected ';' after struct}} -- 2.40.0