From 7bdcc4a9da8ccbafb15872083f551366cdaf3b51 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 10 Apr 2012 01:32:12 +0000 Subject: Disambiguation of '[[': * In C++11, '[[' is ill-formed unless it starts an attribute-specifier. Reject array sizes and array indexes which begin with a lambda-expression. Recover by parsing the lambda as a lambda. * In Objective-C++11, either '[' could be the start of a message-send. Fully disambiguate this case: it turns out that the grammars of message-sends, lambdas and attributes do not actually overlap. Accept any occurrence of '[[' where either '[' starts a message send, but reject a lambda in an array index just like in C++11 mode. Implement a couple of changes to the attribute wording which occurred after our attributes implementation landed: * In a function-declaration, the attributes go after the exception specification, not after the right paren. * A reference type can have attributes applied. * An 'identifier' in an attribute can also be a keyword. Support for alternative tokens (iso646 keywords) in attributes to follow. And some bug fixes: * Parse attributes after declarator-ids, even if they are not simple identifiers. * Do not accept attributes after a parenthesized declarator. * Accept attributes after an array size in a new-type-id. * Partially disamiguate 'delete' followed by a lambda. More work is required here for the case where the lambda-introducer is '[]'. llvm-svn: 154369 --- clang/test/Parser/cxx0x-attributes.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'clang/test/Parser/cxx0x-attributes.cpp') diff --git a/clang/test/Parser/cxx0x-attributes.cpp b/clang/test/Parser/cxx0x-attributes.cpp index 198da77..b208735 100644 --- a/clang/test/Parser/cxx0x-attributes.cpp +++ b/clang/test/Parser/cxx0x-attributes.cpp @@ -5,11 +5,17 @@ int [[]] between_attr; int after_attr [[]]; int * [[]] ptr_attr; +int & [[]] ref_attr = after_attr; +int && [[]] rref_attr = 0; int array_attr [1] [[]]; alignas(8) int aligned_attr; [[test::valid(for 42 [very] **** '+' symbols went on a trip; the end.)]] int garbage_attr; void fn_attr () [[]]; +void noexcept_fn_attr () noexcept [[]]; +struct MemberFnOrder { + virtual void f() const volatile && noexcept [[]] final = 0; +}; class [[]] class_attr {}; extern "C++" [[]] int extern_attr; template [[]] void template_attr (); @@ -17,10 +23,10 @@ template [[]] void template_attr (); int comma_attr [[,]]; // expected-error {{expected identifier}} int scope_attr [[foo::]]; // expected-error {{expected identifier}} +int (paren_attr) [[]]; // expected-error {{an attribute list cannot appear here}} unsigned [[]] int attr_in_decl_spec; // expected-error {{expected unqualified-id}} -int & [[]] ref_attr = after_attr; // expected-error {{an attribute list cannot appear here}} class foo { - void after_const_attr () const [[]]; // expected-error {{expected body of lambda expression}} + void const_after_attr () [[]] const; // expected-error {{expected ';'}} }; extern "C++" [[]] { } // expected-error {{an attribute list cannot appear here}} [[]] template void before_template_attr (); // expected-error {{an attribute list cannot appear here}} @@ -58,6 +64,9 @@ void foo () { [[]] try { } [[]] catch (...) { // expected-error {{an attribute list cannot appear here}} } - + struct S { int arr[2]; } s; + (void)s.arr[ [] { return 0; }() ]; // expected-error {{C++11 only allows consecutive left square brackets when introducing an attribute}} + int n = __builtin_offsetof(S, arr[ [] { return 0; }() ]); // expected-error {{C++11 only allows consecutive left square brackets when introducing an attribute}} + [[]] return; } -- cgit v1.1