36 lines · c
1// RUN: %clang_cc1 -triple x86_64-linux -std=c17 -verify=expected,norounding %s2// RUN: %clang_cc1 -triple x86_64-linux -std=gnu17 -verify=expected,norounding %s3// RUN: %clang_cc1 -triple x86_64-linux -std=c17 -verify=expected,rounding %s -frounding-math4// RUN: %clang_cc1 -triple x86_64-linux -std=gnu17 -verify=expected,rounding %s -frounding-math5 6#define fold(x) (__builtin_constant_p(x) ? (x) : (x))7 8double a = 1.0 / 3.0;9 10#define f(n) ((n) * (1.0 / 3.0))11_Static_assert(fold((int)f(3)) == 1, "");12 13typedef int T[fold((int)f(3))];14typedef int T[1];15 16enum Enum { enum_a = (int)f(3) };17 18struct Bitfield {19 unsigned int n : 1;20 unsigned int m : fold((int)f(3));21};22 23void bitfield(struct Bitfield *b) {24 b->n = (int)(6 * (1.0 / 3.0)); // norounding-warning {{changes value from 2 to 0}}25}26 27void vlas(void) {28 // This is always a VLA due to its syntactic form.29 typedef int vla1[(int)(-3 * (1.0 / 3.0))];30 struct X1 { vla1 v; }; // expected-error {{fields must have a constant size}}31 32 // This is always folded to a constant.33 typedef int vla2[fold((int)(-3 * (1.0 / 3.0)))]; // expected-error {{negative size}}34 struct X2 { vla2 v; };35}36