Home | History | Annotate | Download | only in Parser
      1 // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s
      2 
      3 // Declaration syntax checks
      4 [[]] int before_attr;
      5 int [[]] between_attr;
      6 int after_attr [[]];
      7 int * [[]] ptr_attr;
      8 int array_attr [1] [[]];
      9 alignas(8) int aligned_attr;
     10 [[test::valid(for 42 [very] **** '+' symbols went on a trip; the end.)]]
     11   int garbage_attr;
     12 void fn_attr () [[]];
     13 class [[]] class_attr {};
     14 extern "C++" [[]] int extern_attr;
     15 template <typename T> [[]] void template_attr ();
     16 [[]] [[]] int [[]] [[]] multi_attr [[]] [[]];
     17 
     18 int comma_attr [[,]]; // expected-error {{expected identifier}}
     19 int scope_attr [[foo::]]; // expected-error {{expected identifier}}
     20 unsigned [[]] int attr_in_decl_spec; // expected-error {{expected unqualified-id}}
     21 int & [[]] ref_attr = after_attr; // expected-error {{an attribute list cannot appear here}}
     22 class foo {
     23   void after_const_attr () const [[]]; // expected-error {{expected body of lambda expression}} expected-error {{array has incomplete element type 'void'}}
     24 };
     25 extern "C++" [[]] { } // expected-error {{an attribute list cannot appear here}}
     26 [[]] template <typename T> void before_template_attr (); // expected-error {{an attribute list cannot appear here}}
     27 [[]] namespace ns { int i; } // expected-error {{an attribute list cannot appear here}}
     28 [[]] static_assert(true, ""); //expected-error {{an attribute list cannot appear here}}
     29 [[]] asm(""); // expected-error {{an attribute list cannot appear here}}
     30 
     31 [[]] using ns::i; // expected-error {{an attribute list cannot appear here}}
     32 [[]] using namespace ns;
     33 
     34 // Argument tests
     35 alignas int aligned_no_params; // expected-error {{expected '('}}
     36 alignas(i) int aligned_nonconst; // expected-error {{'aligned' attribute requires integer constant}}
     37 
     38 // Statement tests
     39 void foo () {
     40   [[]] ;
     41   [[]] { }
     42   [[]] if (0) { }
     43   [[]] for (;;);
     44   [[]] do {
     45     [[]] continue;
     46   } while (0);
     47   [[]] while (0);
     48 
     49   [[]] switch (i) {
     50     [[]] case 0:
     51     [[]] default:
     52       [[]] break;
     53   }
     54 
     55   [[]] goto there;
     56   [[]] there:
     57 
     58   [[]] try {
     59   } [[]] catch (...) { // expected-error {{an attribute list cannot appear here}}
     60   }
     61 
     62   [[]] return;
     63 }
     64