brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.3 KiB · 57a77f8 Raw
97 lines · c
1// RUN: %clang_cc1 -verify -std=c2x %s2 3/* WG14 N2927: yes4 * Not-so-magic: typeof5 */6 7// These examples originated in WG14 N2927 but were modified to test particular8// compiler behaviors. Each of these examples come from C2x 6.7.2.5.9 10// EXAMPLE 111typeof(1 + 1) func();12int func();13 14// EXAMPLE 215const _Atomic int purr = 0;16const int meow = 1;17const char *const mew[] = {18	"aardvark",19	"bluejay",20	"catte",21};22 23extern typeof_unqual(purr) plain_purr;24extern int plain_purr;25 26extern typeof(_Atomic typeof(meow)) atomic_meow;27extern const _Atomic int atomic_meow;28 29extern typeof(mew) mew_array;30extern const char *const mew_array[3];31 32extern typeof_unqual(mew) mew2_array;33extern const char *mew2_array[3];34 35// EXAMPLE 336void foo(int argc, char *argv[]) { // expected-note 2 {{declared here}}37  _Static_assert(sizeof(typeof('p')) == sizeof(int));38  _Static_assert(sizeof(typeof('p')) == sizeof('p'));39  _Static_assert(sizeof(typeof((char)'p')) == sizeof(char));40  _Static_assert(sizeof(typeof((char)'p')) == sizeof((char)'p'));41  _Static_assert(sizeof(typeof("meow")) == sizeof(char[5]));42  _Static_assert(sizeof(typeof("meow")) == sizeof("meow"));43  _Static_assert(sizeof(typeof(argc)) == sizeof(int));44  _Static_assert(sizeof(typeof(argc)) == sizeof(argc));45  _Static_assert(sizeof(typeof(argv)) == sizeof(char**));46  _Static_assert(sizeof(typeof(argv)) == sizeof(argv)); // expected-warning {{sizeof on array function parameter will return size of 'char **' instead of 'char *[]'}}47 48  _Static_assert(sizeof(typeof_unqual('p')) == sizeof(int));49  _Static_assert(sizeof(typeof_unqual('p')) == sizeof('p'));50  _Static_assert(sizeof(typeof_unqual((char)'p')) == sizeof(char));51  _Static_assert(sizeof(typeof_unqual((char)'p')) == sizeof((char)'p'));52  _Static_assert(sizeof(typeof_unqual("meow")) == sizeof(char[5]));53  _Static_assert(sizeof(typeof_unqual("meow")) == sizeof("meow"));54  _Static_assert(sizeof(typeof_unqual(argc)) == sizeof(int));55  _Static_assert(sizeof(typeof_unqual(argc)) == sizeof(argc));56  _Static_assert(sizeof(typeof_unqual(argv)) == sizeof(char**));57  _Static_assert(sizeof(typeof_unqual(argv)) == sizeof(argv)); // expected-warning {{sizeof on array function parameter will return size of 'char **' instead of 'char *[]'}}58}59 60// EXAMPLE 461void bar(int argc) {62  extern int val;63  extern typeof(typeof_unqual(typeof(argc)))val;64}65 66// EXAMPLE 5 is tested by n2927_2.c because it is a codegen test.67 68// EXAMPLE 669extern const char *y[4];70extern typeof(typeof(const char*)[4]) y;71 72// EXAMPLE 773void f(int);74 75void g(double);76typeof(f(5)) g(double x);          // g has type "void(double)"77 78extern void (*h)(double);79extern typeof(g)* h;               // h has type "void(*)(double)"80extern typeof(true ? g : 0) h;  // h has type "void(*)(double)"81 82void j(double *, double **);83void j(double A[5], typeof(A)* B); // j has type "void(double*, double**)"84 85extern typeof(double[]) D;         // D has an incomplete type86 87extern double C[2];88extern typeof(D) C;                // C has type "double[2]"89 90typeof(D) D = { 5, 8.9, 0.1, 99 }; // D is now completed to "double[4]"91extern double E[4];92extern typeof(D) E;                // E has type "double[4]" from D�s completed type93 94// GH64713 -- this used to trigger an infinite loop when creating the function95// declaration for F from the function designator specified by typeof.96typeof(int(int)) F;                // F has type "int(int)"97