diff options
Diffstat (limited to 'gcc/testsuite/gcc.dg/cpp')
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/19951025-1.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/19990703-1.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/20000625-1.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/20000625-2.c | 1 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/macro1.c | 72 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/paste1.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/paste2.c | 115 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/paste3.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/paste4.c | 14 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/strify1.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/strify2.c | 45 |
11 files changed, 284 insertions, 3 deletions
diff --git a/gcc/testsuite/gcc.dg/cpp/19951025-1.c b/gcc/testsuite/gcc.dg/cpp/19951025-1.c index c243df0..283b5f5 100644 --- a/gcc/testsuite/gcc.dg/cpp/19951025-1.c +++ b/gcc/testsuite/gcc.dg/cpp/19951025-1.c @@ -1,4 +1,4 @@ /* { dg-do preprocess } */ /* { dg-error "include expects" "" { target *-*-* } 4 } */ -/* { dg-warning "no newline" "" { target *-*-* } 5 } */ +/* { dg-error "newline at end" "" { target *-*-* } 4 } */ #include /\ diff --git a/gcc/testsuite/gcc.dg/cpp/19990703-1.c b/gcc/testsuite/gcc.dg/cpp/19990703-1.c index 88dc9e6..c3ac233 100644 --- a/gcc/testsuite/gcc.dg/cpp/19990703-1.c +++ b/gcc/testsuite/gcc.dg/cpp/19990703-1.c @@ -14,7 +14,7 @@ int main(void) { - char *x = SP1(0,MZ); + char *x = SP1(0,MZ); /* { dg-warning "valid preprocessing token" "" } */ char *y = "0-0"; /* should be the expansion of SP1(0,MZ) */ if(strcmp(x, y)) diff --git a/gcc/testsuite/gcc.dg/cpp/20000625-1.c b/gcc/testsuite/gcc.dg/cpp/20000625-1.c index 9193e39..ddfdb99 100644 --- a/gcc/testsuite/gcc.dg/cpp/20000625-1.c +++ b/gcc/testsuite/gcc.dg/cpp/20000625-1.c @@ -11,6 +11,6 @@ main(void) { goto socket; - ENTRY(socket) + ENTRY(socket) /* { dg-warning "valid preprocessing token" "" } */ return 0; } diff --git a/gcc/testsuite/gcc.dg/cpp/20000625-2.c b/gcc/testsuite/gcc.dg/cpp/20000625-2.c index e983450..e0dd35c 100644 --- a/gcc/testsuite/gcc.dg/cpp/20000625-2.c +++ b/gcc/testsuite/gcc.dg/cpp/20000625-2.c @@ -7,6 +7,7 @@ #define xstr(x) #x const char a[] = str(symbol_version(getrlimit, GLIBC_2.0)); +/* { dg-warning "valid preprocessing token" "" { target *-*-* } 9 } */ const char b[] = str(getrlimit@GLIBC_2.0); const char c[] = "getrlimit@GLIBC_2.0"; diff --git a/gcc/testsuite/gcc.dg/cpp/macro1.c b/gcc/testsuite/gcc.dg/cpp/macro1.c new file mode 100644 index 0000000..60347ed --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/macro1.c @@ -0,0 +1,72 @@ +/* Copyright (C) 2000 Free Software Foundation, Inc. */ + +/* { dg-do run } */ + +/* Tests various macros are correctly expanded. */ + +extern int puts (const char *); +extern void abort (void); +#define err(str) do { puts(str); abort(); } while (0) + +#define j(x, y) x + y +#define k(x, y) j(x + 2, y + + +int q(int x) {return x + 40;} +int B(int x) {return x + 20;} +int foo(int x) {return x + 10;} +int bar(int x, int y) {return x + y;} +int baz(int x, int y) {return x + y;} +int toupper(int x) {return x + 32;} + +int main (int argc, char *argv[]) +{ +#define q(x) x + if (q(q)(2) != 42) + err ("q"); + +#define A(x) B(x) + if (A(A(2)) != 42) + err ("A"); + +#define E(x) A x +#define F (22) + if (E(F) != 42) + err ("E(F)"); + +#define COMMA , +#define NASTY(a) j(a 37) + if (NASTY (5 COMMA) != 42) + err ("NASTY"); + +#define bar(x, y) foo(x(y, 0)) +#define apply(x, y) foo(x(y, 22)) +#define bam bar + if (bar(bar, 32) != 42) /* foo(bar(32, 0)). */ + err ("bar bar"); + if (bar(bam, 32) != 42) /* Same. */ + err ("bar bam"); + if (apply(bar, baz) != 42) /* foo(foo(baz(22, 0))). */ + err ("apply bar baz"); + +#define __tobody(c, f) f (c) +#define toupper(c) __tobody (c, toupper) + if (toupper (10) != 42) /* toupper (10). */ + err ("toupper"); + + /* This looks like it has too many ')', but it hasn't. */ + if (k(1, 4) 35) != 42) + err ("k"); + + /*#define B(x) Z B(x) +#define XEXP(RTX, N) RTX->fld[N].rtx +#define PATTERN(INSN) XEXP(INSN, 3) +#define COST(X) XEXP (XEXP (x, 0), 0) +#define M(a) OK M (a) +#define stpcpy(a) M(a) +#define C(x) A(x) +XEXP (PATTERN (insn), i); +XEXP (XEXP (insn, 3), i); +COST (b)*/ + + return 0; +} diff --git a/gcc/testsuite/gcc.dg/cpp/paste1.c b/gcc/testsuite/gcc.dg/cpp/paste1.c new file mode 100644 index 0000000..7b07f74 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/paste1.c @@ -0,0 +1,10 @@ +/* Copyright (C) 2000 Free Software Foundation, Inc. */ + +/* { dg-do preprocess } */ + +/* Test operator ## semantics. */ + +#define bad1 ## owt /* { dg-error "cannot" "## at objlike start" } */ +#define bad2 owt ## /* { dg-error "cannot" "## at objlike end" } */ +#define bad3(x) ## x /* { dg-error "cannot" "## at funlike start" } */ +#define bad4(x) x ## /* { dg-error "cannot" "## at funlike end" } */ diff --git a/gcc/testsuite/gcc.dg/cpp/paste2.c b/gcc/testsuite/gcc.dg/cpp/paste2.c new file mode 100644 index 0000000..1ce13a5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/paste2.c @@ -0,0 +1,115 @@ +/* Copyright (C) 2000 Free Software Foundation, Inc. */ + +/* { dg-do run } */ +/* { dg-options "-std=c99 -pedantic-errors" } */ + +/* Test ## behaviour and corner cases thoroughly. The macro expander + failed many of these during development. */ + +#include <string.h> + +#ifndef __WCHAR_TYPE__ +#define __WCHAR_TYPE__ int +#endif +typedef __WCHAR_TYPE__ wchar_t; + +extern int puts (const char *); +extern void abort (void); +#define err(str) do { puts(str); abort(); } while (0) + +#define EMPTY +#define str(x) #x +#define xstr(x) str(x) +#define glue(x, y) x ## y +#define xglue(x, y) glue (x, y) +#define glue3(x, y, z) x ## y ## z +#define glue_var(x, ...) x ## __VA_ARGS__ + +#define __muldi3 __NDW(mul, 3 = 50) +#define __NDW(a,b) __ ## a ## di ## b +#define m3 NDW() +#define NDW(x) m3 ## x = 50 +#define five 5 +#define fifty int fif ## ty + +/* Defines a function called glue, returning what it is passed. */ +int glue (glue,) (int x) +{ + return x; +} + +int main () +{ + /* m3 and __muldi3 would sometimes cause an infinite loop. Ensure + we only expand fifty once. */ + fifty = 50, m3, __muldi3; + + /* General glue and macro expanding test. */ + int five0 = xglue (glue (fi, ve), 0); + + /* Tests only first and last tokens are pasted, and pasting to form + the != operator. Should expand to: if (five0 != 50). */ + if (glue3 (fi, ve0 !,= glue (EMPTY 5, 0))) + err ("five0 != 50"); + + /* Test varags pasting, and pasting to form the >> operator. */ + if (glue_var(50 >, > 1 != 25)) + err ("Operator >> pasting"); + + /* The LHS should not attempt to expand twice, and thus becomes a + call to the function glue, but the RHS should fully expand. */ + if (glue (gl, ue) (12) != glue (xgl, ue) (1, 2)) + err ("Recursive macros"); + + /* Test placemarker pasting. The glued lines should all appear + neatly in the same column and below each other, though we don't + test that here. */ + { + int glue3(a, b, ) = 1, glue3(a,,) = 1; + glue3(a, , b)++; + glue3(, a, b)++; + glue3(,a,)++; + glue3(,,a)++; + if (a != 3 || ab != 3 glue3(,,)) + err ("Placemarker pasting"); + } + + /* Test that macros in arguments are not expanded. */ + { + int glue (EMPTY,1) = 123, glue (T, EMPTY) = 123; + if (EMPTY1 != 123 || TEMPTY != 123) + err ("Pasted arguments macro expanding"); + } + + /* Test various paste combinations. */ + { + const wchar_t* wc_array = glue(L, "wide string"); + wchar_t wc = glue(L, 'w'); + const char * hh = xstr(xglue(glue(%, :), glue(%, :))); + int array glue (<, :) 1 glue (:, >) = glue(<, %) 1 glue(%, >); + int x = 4; + + if (array[0] != 1) + err ("Digraph pasting"); + + x glue (>>, =) 1; /* 2 */ + x glue (<<, =) 1; /* 4 */ + x glue (*, =) 2; /* 8 */ + x glue (+, =) 100; /* 108 */ + x glue (-, =) 50; /* 58 */ + x glue (/, =) 2; /* 29 */ + x glue (%, =) 20; /* 9 */ + x glue (&, =) 254; /* 8 */ + x glue (|, =) 16; /* 24 */ + x glue (^, =) 18; /* 10 */ + + if (x != 10 || 0 glue (>, =) 1 glue (|, |) 1 glue (<, =) 0) + err ("Various operator pasting"); + if (strcmp (hh, "%:%:")) + err ("Pasted digraph spelling"); + if ((glue (., 0) glue (=, =) .0) + (glue3 (1.0e, +, 1) == 10.0) != 2) + err ("Pasted numbers"); + } + + return 0; +} diff --git a/gcc/testsuite/gcc.dg/cpp/paste3.c b/gcc/testsuite/gcc.dg/cpp/paste3.c new file mode 100644 index 0000000..0c9c52d --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/paste3.c @@ -0,0 +1,14 @@ +/* Copyright (C) 2000 Free Software Foundation, Inc. */ + +/* { dg-do compile } */ + +#define plus + + +void foo() +{ + int a, b = 1; + + /* The correct "a = 1 + ++b" will compile. + The incorrect "a = 1 +++b" won't. */ + a = 1 plus++b; +} diff --git a/gcc/testsuite/gcc.dg/cpp/paste4.c b/gcc/testsuite/gcc.dg/cpp/paste4.c new file mode 100644 index 0000000..fac1d43 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/paste4.c @@ -0,0 +1,14 @@ +/* Copyright (C) 2000 Free Software Foundation, Inc. */ +/* { dg-do compile } */ + +/* Since 1.0e and + form the pasted token, 1 is a separate token and + so should be output with a preceding space. The old preprocessor + gets this wrong. */ + +#define glue(x, y) x ## y + +int main () +{ + double d = glue (1.0e, +1); /* { dg-error "floating const|parse error" } */ + return 0; +} diff --git a/gcc/testsuite/gcc.dg/cpp/strify1.c b/gcc/testsuite/gcc.dg/cpp/strify1.c new file mode 100644 index 0000000..3535540 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/strify1.c @@ -0,0 +1,10 @@ +/* Copyright (C) 2000 Free Software Foundation, Inc. */ + +/* { dg-do preprocess } */ + +/* Test operator # semantics. */ + +#define OK1 # /* No problem. */ +#define OK2(x) x#x /* No problem. */ +#define bad1(x) # /* { dg-error "followed by a macro parameter" "#1" } */ +#define bad2(x) #y /* { dg-error "followed by a macro parameter" "#2" } */ diff --git a/gcc/testsuite/gcc.dg/cpp/strify2.c b/gcc/testsuite/gcc.dg/cpp/strify2.c new file mode 100644 index 0000000..ddde976 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/strify2.c @@ -0,0 +1,45 @@ +/* Copyright (C) 2000 Free Software Foundation, Inc. */ + +/* { dg-do run } */ +/* { dg-options "-std=c99 -pedantic-errors" } */ + +/* Tests a whole bunch of things are correctly stringified. */ + +extern int strcmp (const char *, const char *); +extern int puts (const char *); +extern void abort (void); +#define err(str) do { puts(str); abort(); } while (0) + +#define str(x) #x +#define xstr(x) str(x) +#define strvar(...) #__VA_ARGS__ + +int main (int argc, char *argv[]) +{ + str (\); /* { dg-warning "valid string" "str(\)" } */ + str (\\\); /* { dg-warning "valid string" "str(\\\)" } */ + + /* This also serves as a useful test of the value of __INCLUDE_LEVEL. */ + if (strcmp (xstr (__INCLUDE_LEVEL__), "0")) + err ("macro expansion"); + + if (strcmp(str (__INCLUDE_LEVEL__), "__INCLUDE_LEVEL__")) + err ("macro name"); + + if (strcmp(str ("s\n"), "\"s\\n\"")) + err ("quoted string"); + + if (strcmp (str (a € b), "a \200 b")) + err ("unprintable char"); + + if (strcmp (str ( a b@ c ), "a b@ c")) + err ("internal whitespace"); + + if (strcmp (str(a \n), "a \n")) + err ("backslash token"); + + if (strcmp (strvar (foo, bar), "foo, bar")) + err ("variable arguments"); + + return 0; +} |