diff --git a/tests2/55_lshift_type.c b/tests2/55_lshift_type.c new file mode 100644 index 00000000..aa3e51a1 --- /dev/null +++ b/tests2/55_lshift_type.c @@ -0,0 +1,52 @@ +/* $Id: lshift-type.c 53089 2012-07-06 11:18:26Z vinc17/ypig $ + +Tests on left-shift type, written by Vincent Lefevre . + +ISO C99 TC3 says: [6.5.7#3] "The integer promotions are performed on +each of the operands. The type of the result is that of the promoted +left operand." +*/ + +#include + +#define PTYPE(M) ((M) < 0 || -(M) < 0 ? -1 : 1) * (int) sizeof((M)+0) +#define CHECK(X,T) check(#X, PTYPE(X), PTYPE((X) << (T) 1)) +#define TEST1(X,T) do { CHECK(X,T); CHECK(X,unsigned T); } while (0) +#define TEST2(X) \ + do \ + { \ + TEST1((X),short); \ + TEST1((X),int); \ + TEST1((X),long); \ + TEST1((X),long long); \ + } \ + while (0) +#define TEST3(X,T) do { TEST2((T)(X)); TEST2((unsigned T)(X)); } while (0) +#define TEST4(X) \ + do \ + { \ + TEST3((X),short); \ + TEST3((X),int); \ + TEST3((X),long); \ + TEST3((X),long long); \ + } \ + while (0) + +static int debug, nfailed = 0; + +static void check (const char *s, int arg1, int shift) +{ + int failed = arg1 != shift; + if (debug || failed) + printf ("%s %d %d\n", s, arg1, shift); + nfailed += failed; +} + +int main (int argc, char **argv) +{ + debug = argc > 1; + TEST4(1); + TEST4(-1); + printf ("%d test(s) failed\n", nfailed); + return nfailed != 0; +} diff --git a/tests2/55_lshift_type.expect b/tests2/55_lshift_type.expect new file mode 100644 index 00000000..8523767a --- /dev/null +++ b/tests2/55_lshift_type.expect @@ -0,0 +1 @@ +0 test(s) failed diff --git a/tests2/Makefile b/tests2/Makefile index b57028b2..bf4c2cd1 100644 --- a/tests2/Makefile +++ b/tests2/Makefile @@ -61,7 +61,8 @@ TESTS= 00_assignment.test \ 50_logical_second_arg.test \ 51_static.test \ 52_unnamed_enum.test \ - 54_goto.test + 54_goto.test \ + 55_lshift_type.test # 30_hanoi.test \ # seg fault in the code, gcc as well # 34_array_assignment.test \ # array assignment is not in C standard