"Fossies" - the Fresh Open Source Software Archive

Member "cfe-9.0.0.src/test/Parser/c2x-attributes.c" (14 May 2019, 3229 Bytes) of package /linux/misc/cfe-9.0.0.src.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "c2x-attributes.c": 8.0.1_vs_9.0.0.

    1 // RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify %s
    2 // RUN: %clang_cc1 -fsyntax-only -std=gnu2x -verify %s
    3 
    4 enum [[]] E {
    5   One [[]],
    6   Two,
    7   Three [[]]
    8 };
    9 
   10 enum [[]] { Four };
   11 [[]] enum E2 { Five }; // expected-error {{misplaced attributes}}
   12 
   13 // FIXME: this diagnostic can be improved.
   14 enum { [[]] Six }; // expected-error {{expected identifier}}
   15 
   16 // FIXME: this diagnostic can be improved.
   17 enum E3 [[]] { Seven }; // expected-error {{expected identifier or '('}}
   18 
   19 struct [[]] S1 {
   20   int i [[]];
   21   int [[]] j;
   22   int k[10] [[]];
   23   int l[[]][10];
   24   [[]] int m, n;
   25   int o [[]] : 12;
   26 };
   27 
   28 [[]] struct S2 { int a; }; // expected-error {{misplaced attributes}}
   29 struct S3 [[]] { int a; }; // expected-error {{an attribute list cannot appear here}}
   30 
   31 union [[]] U {
   32   double d [[]];
   33   [[]] int i;
   34 };
   35 
   36 [[]] union U2 { double d; }; // expected-error {{misplaced attributes}}
   37 union U3 [[]] { double d; }; // expected-error {{an attribute list cannot appear here}}
   38 
   39 struct [[]] IncompleteStruct;
   40 union [[]] IncompleteUnion;
   41 enum [[]] IncompleteEnum;
   42 enum __attribute__((deprecated)) IncompleteEnum2;
   43 
   44 [[]] void f1(void);
   45 void [[]] f2(void);
   46 void f3 [[]] (void);
   47 void f4(void) [[]];
   48 
   49 void f5(int i [[]], [[]] int j, int [[]] k);
   50 
   51 void f6(a, b) [[]] int a; int b; { // expected-error {{an attribute list cannot appear here}}
   52 }
   53 
   54 // FIXME: technically, an attribute list cannot appear here, but we currently
   55 // parse it as part of the return type of the function, which is reasonable
   56 // behavior given that we *don't* want to parse it as part of the K&R parameter
   57 // declarations. It is disallowed to avoid a parsing ambiguity we already
   58 // handle well.
   59 int (*f7(a, b))(int, int) [[]] int a; int b; {
   60   return 0;
   61 }
   62 
   63 [[]] int a, b;
   64 int c [[]], d [[]];
   65 
   66 void f8(void) [[]] {
   67   [[]] int i, j;
   68   int k, l [[]];
   69 }
   70 
   71 [[]] void f9(void) {
   72   int i[10] [[]];
   73   int (*fp1)(void)[[]];
   74   int (*fp2 [[]])(void);
   75 
   76   int * [[]] *ipp;
   77 }
   78 
   79 void f10(int j[static 10] [[]], int k[*] [[]]);
   80 
   81 void f11(void) {
   82   [[]] {}
   83   [[]] if (1) {}
   84 
   85   [[]] switch (1) {
   86   [[]] case 1: [[]] break;
   87   [[]] default: break;
   88   }
   89 
   90   goto foo;
   91   [[]] foo: (void)1;
   92 
   93   [[]] for (;;);
   94   [[]] while (1);
   95   [[]] do [[]] { } while(1);
   96 
   97   [[]] (void)1;
   98 
   99   [[]];
  100 
  101   (void)sizeof(int [4][[]]);
  102   (void)sizeof(struct [[]] S3 { int a [[]]; });
  103 
  104   [[]] return;
  105 }
  106 
  107 [[attr]] void f12(void); // expected-warning {{unknown attribute 'attr' ignored}}
  108 [[vendor::attr]] void f13(void); // expected-warning {{unknown attribute 'attr' ignored}}
  109 
  110 // Ensure that asm statements properly handle double colons.
  111 void test_asm(void) {
  112   asm("ret" :::);
  113   asm("foo" :: "r" (xx)); // expected-error {{use of undeclared identifier 'xx'}}
  114 }
  115 
  116 // Do not allow 'using' to introduce vendor attribute namespaces.
  117 [[using vendor: attr1, attr2]] void f14(void); // expected-error {{expected ']'}} \
  118                                                // expected-warning {{unknown attribute 'vendor' ignored}} \
  119                                                // expected-warning {{unknown attribute 'using' ignored}}
  120 
  121 struct [[]] S4 *s; // expected-error {{an attribute list cannot appear here}}
  122 struct S5 {};
  123 int c = sizeof(struct [[]] S5); // expected-error {{an attribute list cannot appear here}}