brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · af0ca6d Raw
74 lines · c
1// RUN: %clang_cc1 -fsyntax-only -verify=silent %s2// RUN: %clang_cc1 -fsyntax-only -verify=cpp -x c++ %s3// RUN: %clang_cc1 -fsyntax-only -pedantic -Wno-comment -verify %s4// RUN: %clang_cc1 -fsyntax-only -pedantic -Wno-comment -std=c89 -verify %s5// RUN: %clang_cc1 -fsyntax-only -pedantic -Wno-comment -std=c99 -verify %s6// RUN: %clang_cc1 -fsyntax-only -pedantic -Wno-comment -std=c11 -verify %s7// RUN: %clang_cc1 -fsyntax-only -pedantic -Wno-comment -std=c17 -verify %s8// RUN: %clang_cc1 -fsyntax-only -pedantic -Wno-comment -std=c2x -verify=silent %s9 10// silent-no-diagnostics11 12// Reject definitions in __builtin_offsetof13// https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm14int simple(void) {15  return __builtin_offsetof(struct A // cpp-error {{'A' cannot be defined in a type specifier}} \16                                        expected-warning {{defining a type within '__builtin_offsetof' is a C23 extension}}17  {18    int a;19    struct B // expected-warning {{defining a type within '__builtin_offsetof' is a C23 extension}}20    {21      int c;22      int d;23    } x;24  }, a);25}26 27int anonymous_struct(void) {28  return __builtin_offsetof(struct // cpp-error-re {{'(unnamed struct at {{.*}})' cannot be defined in a type specifier}} \29                                      expected-warning {{defining a type within '__builtin_offsetof' is a C23 extension}}30  {31    int a;32    int b;33  }, a);34}35 36int struct_in_second_param(void) {37  struct A {38    int a, b;39    int x[20];40  };41  return __builtin_offsetof(struct A, x[sizeof(struct B{int a;})]); // cpp-error {{'B' cannot be defined in a type specifier}}42}43 44 45#define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER)46 47 48int macro(void) {49  return offsetof(struct A // cpp-error {{'A' cannot be defined in a type specifier}} \50                              expected-warning 2 {{defining a type within 'offsetof' is a C23 extension}}51  {52    int a;53    struct B // verifier seems to think the error is emitted by the macro54             // In fact the location of the error is "B" on the line above55    {56      int c;57      int d;58    } x;59  }, a);60}61 62#undef offsetof63 64#define offsetof(TYPE, MEMBER) (&((TYPE *)0)->MEMBER)65 66// no warning for traditional offsetof as a function-like macro67int * macro_func(void) {68  return offsetof(struct A // cpp-error {{'A' cannot be defined in a type specifier}}69  {70    int a;71    int b;72  }, a);73}74