Commit 74f215d7 by Neil Booth

19960224-2.c, [...]: Update tests for new diagnostic messages.

	* gcc.dg/cpp/19960224-2.c, 20000625-2.c, cxxcom2.c, directiv.c,
	endif.c, if-4.c, if-5.c, if-mop.c, macsyntx.c, paste2.c, paste6.c,
	paste8.c, redef2.c, strify2.c, strp1.c, tr-warn1.c, tr-warn3.c,
	tr-warn6.c, undef1.c, undef2.c, widestr1.c: Update tests for
	new diagnostic messages.

	* gcc.dg/cpp/macro3.c: New tests.

From-SVN: r37099
parent 93c80368
...@@ -2,5 +2,5 @@ ...@@ -2,5 +2,5 @@
#if 0 #if 0
#if 0 #if 0
#endif / /* { dg-error "text after #endif" "text after #endif" } */ #endif / /* { dg-warning "extra tokens" "extra tokens after #endif" } */
#endif #endif
/* More paste corner cases from glibc. */ /* More paste corner cases from glibc. */
/* { dg-do run } */ /* { dg-do run } */
#include <stdlib.h>
#include <string.h>
#define symbol_version(name, version) name##@##version #define symbol_version(name, version) name##@##version
#define str(x) xstr(x) #define str(x) xstr(x)
#define xstr(x) #x #define xstr(x) #x
const char a[] = str(symbol_version(getrlimit, GLIBC_2.0)); const char a[] = str(symbol_version(getrlimit, GLIBC_2.0));
/* { dg-warning "valid preprocessing token" "" { target *-*-* } 8 } */ /* { dg-warning "valid preprocessing token" "" { target *-*-* } 11 } */
const char b[] = str(getrlimit@GLIBC_2.0); const char b[] = str(getrlimit@GLIBC_2.0);
const char c[] = "getrlimit@GLIBC_2.0"; const char c[] = "getrlimit@GLIBC_2.0";
#include <stdlib.h>
#include <string.h>
int int
main(void) main(void)
{ {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/* { dg-options "-pedantic -std=c89" } */ /* { dg-options "-pedantic -std=c89" } */
/* This is an extension and therefore gets a warning. */ /* This is an extension and therefore gets a warning. */
#line 5 "cxx-comments-2.c" 3 /* { dg-warning "garbage at end" "#line extension" } */ #line 5 "cxx-comments-2.c" 3 /* { dg-warning "extra tokens" "#line extension" } */
/* A system header may contain C++ comments irrespective of mode. */ /* A system header may contain C++ comments irrespective of mode. */
// C++ comment is not in C89 { dg-bogus "style comment" "bad warning" } // C++ comment is not in C89 { dg-bogus "style comment" "bad warning" }
......
...@@ -28,8 +28,8 @@ EMPTY #define bar ...@@ -28,8 +28,8 @@ EMPTY #define bar
/* Check that directives always start a line, even if in middle of /* Check that directives always start a line, even if in middle of
macro expansion. */ macro expansion. */
#define func(x) x #define func(x) x
func (2 /* { dg-error "unterminated argument" } */ func (2 /* { dg-error "unterminated" "" { target *-*-* } 32 } */
#define foobar /* { dg-error "may not be used inside" } */ #define foobar /* { dg-error "directives may not" } */
/* For tidiness, I think the directive should still be processed /* For tidiness, I think the directive should still be processed
above. Certainly, continuing to try to find the closing ')' can above. Certainly, continuing to try to find the closing ')' can
......
...@@ -4,12 +4,12 @@ ...@@ -4,12 +4,12 @@
/* You can't get away with this in your own code... */ /* You can't get away with this in your own code... */
#ifdef KERNEL #ifdef KERNEL
#define foo #define foo
#endif KERNEL /* { dg-warning "forbids text after" "good warning" } */ #endif KERNEL /* { dg-warning "extra tokens" "good warning" } */
/* This will provoke a warning because the '3' is an extension. */ /* This will provoke a warning because the '3' is an extension. */
#line 10 "endif-label.c" 3 /* { dg-warning "garbage at end" "#line extension" } */ #line 10 "endif-label.c" 3 /* { dg-warning "extra tokens" "#line extension" } */
/* ... but in a system header, it's acceptable. */ /* ... but in a system header, it's acceptable. */
#ifdef KERNEL #ifdef KERNEL
#define foo #define foo
#endif KERNEL /* { dg-bogus "forbids text after" "bad warning" } */ #endif KERNEL /* { dg-bogus "extra tokens" "bad warning" } */
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
NUL terminated, so we would print garbage after it. */ NUL terminated, so we would print garbage after it. */
/* { dg-do compile } */ /* { dg-do compile } */
#if 1 += 2 /* { dg-error "'\\+=' is not valid" "+= in if" } */ #if 1 += 2 /* { dg-error "is not valid" "+= in if" } */
syntax_error syntax_error
#endif #endif
int foo; int foo;
...@@ -2,11 +2,8 @@ ...@@ -2,11 +2,8 @@
Jakub Jelinek <jakub@redhat.com>. */ Jakub Jelinek <jakub@redhat.com>. */
/* { dg-do preprocess } */ /* { dg-do preprocess } */
#ifdef 0 /* { dg-error "with invalid argument" } */ #ifdef 0 /* { dg-error "macro names" } */
#error not seen
#endif #endif
#ifndef 0 /* { dg-error "with invalid argument" } */ #ifndef 0 /* { dg-error "macro names" } */
#else
#error not seen
#endif #endif
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
/* { dg-do preprocess } */ /* { dg-do preprocess } */
/* Source: Neil Booth. */
/* Various illegal expressions with missing components. */ /* Various illegal expressions with missing components. */
#if /* { dg-error "no expression" "empty #if" } */ #if /* { dg-error "no expression" "empty #if" } */
......
/* { dg-do run } */
/* { dg-options "-std=c99" } */
/* First two tests sourced from a bug report of Thomas Pornin.
Varargs test source Jamie Lokier.
All adapted for the testsuite by Neil Booth, Oct 2000. */
int c(int x)
{
return x;
}
int a(int x)
{
return x;
}
/* Tests various macro abuse is correctly expanded. */
#define c(x) d
#define d(x) c(2)
/* Every GCC <= 2.96 appears to fail this. */
#define a(x) b(
#define b(x) a(
#define apply(...) apply2 (__VA_ARGS__)
#define half(x) ((x) / 2)
#define apply2(f,x) f (x)
extern void abort (void);
extern void exit (int);
int main()
{
/* Expands to c(2). */
if (c(c)(c) != 2)
abort ();
/* Expands to a(2). */
if (a(a)x)2) != 2)
abort ();
if (apply (half, 200) != 100)
abort ();
exit (0);
}
...@@ -28,13 +28,14 @@ ...@@ -28,13 +28,14 @@
#define foo(, X) /* { dg-error "parameter name" } */ #define foo(, X) /* { dg-error "parameter name" } */
#define foo(X, X) /* { dg-error "duplicate" } */ #define foo(X, X) /* { dg-error "duplicate" } */
#define foo(X Y) /* { dg-error "comma" } */ #define foo(X Y) /* { dg-error "comma" } */
#define foo(() /* { dg-error "token may not appear" } */ #define foo(() /* { dg-error "may not appear" } */
#define foo(..., X) /* { dg-error "missing" } */ #define foo(..., X) /* { dg-error "missing" } */
#define foo \ #define foo \
__VA_ARGS__ /* { dg-warning "__VA_ARGS__" } */ __VA_ARGS__ /* { dg-warning "__VA_ARGS__" } */
#define foo(__VA_ARGS__) /* { dg-warning "__VA_ARGS__" } */ #define goo(__VA_ARGS__) /* { dg-warning "__VA_ARGS__" } */
#define foo(...) __VA_ARGS__ /* OK. */ #define hoo(...) __VA_ARGS__ /* OK. */
#define __VA_ARGS__ /* { dg-warning "__VA_ARGS__" } */ #define __VA_ARGS__ /* { dg-warning "__VA_ARGS__" } */
__VA_ARGS__ /* { dg-warning "__VA_ARGS__" } */
/* test # of supplied arguments. */ /* test # of supplied arguments. */
#define none() #define none()
...@@ -43,12 +44,12 @@ __VA_ARGS__ /* { dg-warning "__VA_ARGS__" } */ ...@@ -43,12 +44,12 @@ __VA_ARGS__ /* { dg-warning "__VA_ARGS__" } */
#define var0(...) #define var0(...)
#define var1(x, ...) #define var1(x, ...)
none() /* OK. */ none() /* OK. */
none(ichi) /* { dg-error "too many" } */ none(ichi) /* { dg-error "passed 1" } */
one() /* OK. */ one() /* OK. */
one(ichi) /* OK. */ one(ichi) /* OK. */
one(ichi\ one(ichi\
, ni) /* { dg-error "too many" } */ , ni) /* { dg-error "passed 2" } */
two(ichi) /* { dg-error "not enough" } */ two(ichi) /* { dg-error "requires 2" } */
var0() /* OK. */ var0() /* OK. */
var0(ichi) /* OK. */ var0(ichi) /* OK. */
var1() /* { dg-warning "rest arguments to be used" } */ var1() /* { dg-warning "rest arguments to be used" } */
......
...@@ -56,8 +56,8 @@ int main () ...@@ -56,8 +56,8 @@ int main ()
err ("Operator >> pasting"); err ("Operator >> pasting");
/* The LHS should not attempt to expand twice, and thus becomes a /* The LHS should not attempt to expand twice, and thus becomes a
call to the function glue, but the RHS should fully expand. */ call to the function glue. */
if (glue (gl, ue) (12) != glue (xgl, ue) (1, 2)) if (glue (gl, ue) (12) != 12)
err ("Recursive macros"); err ("Recursive macros");
/* Test placemarker pasting. The glued lines should all appear /* Test placemarker pasting. The glued lines should all appear
...@@ -106,6 +106,8 @@ int main () ...@@ -106,6 +106,8 @@ int main ()
err ("Various operator pasting"); err ("Various operator pasting");
if (strcmp (hh, "%:%:")) if (strcmp (hh, "%:%:"))
err ("Pasted digraph spelling"); err ("Pasted digraph spelling");
/* glue3 here will only work if we paste left-to-right. If a
future implementation does not do this, change the test. */
if ((glue (., 0) glue (=, =) .0) + (glue3 (1.0e, +, 1) == 10.0) != 2) if ((glue (., 0) glue (=, =) .0) + (glue3 (1.0e, +, 1) == 10.0) != 2)
err ("Pasted numbers"); err ("Pasted numbers");
} }
......
...@@ -7,6 +7,6 @@ ...@@ -7,6 +7,6 @@
extern int foo(int x); extern int foo(int x);
#define bar(x) foo(x) #define bar(x) foo(x)
#define baz(x) bar(##x) /* { dg-warning "nothing can be pasted" } */ #define baz(x) bar(##x)
int quux(int y) { return baz(y); } int quux(int y) { return baz(y); } /* { dg-warning "valid preprocessing" } */
...@@ -7,9 +7,9 @@ int foo(int, ...); ...@@ -7,9 +7,9 @@ int foo(int, ...);
a(1) a(1)
a(1, 2, 3) a(1, 2, 3)
#define b(x, y, z...) foo(x, ##y) #define b(x, y, z...) foo(x, ##y)
b(1, 2, 3) /* { dg-warning "pasting would not" } */ b(1, 2, 3) /* { dg-warning "valid preprocessing token" } */
#define c(x, y, z...) foo(x, ##z) #define c(x, y, z...) foo(x, ##z)
c(1, 2) c(1, 2)
c(1, 2, 3) c(1, 2, 3)
#define d(x) foo(##x) /* { dg-warning "nothing can be pasted" } */ #define d(x) fo(##x)
d(1) d(1) /* { dg-warning "valid preprocessing token" } */
...@@ -26,5 +26,5 @@ ...@@ -26,5 +26,5 @@
{ dg-warning "previous" "prev def ro" { target *-*-* } 11 } { dg-warning "previous" "prev def ro" { target *-*-* } 11 }
{ dg-warning "previous" "prev def va" { target *-*-* } 14 } { dg-warning "previous" "prev def va" { target *-*-* } 14 }
{ dg-warning "varargs" "named varargs" { target *-*-* } 14 } { dg-warning "named variable" "named" { target *-*-* } 14 }
{ dg-warning "varargs" "anon varargs" { target *-*-* } 15 } */ { dg-warning "anonymous variable" "anon" { target *-*-* } 15 } */
...@@ -16,7 +16,7 @@ static const char t1[] = "1.1"; ...@@ -16,7 +16,7 @@ static const char t1[] = "1.1";
#define f h #define f h
#define h(a) a+f #define h(a) a+f
static const char s2[] = S( f(1)(2) ); static const char s2[] = S( f(1)(2) );
static const char t2[] = "1+h(2)"; static const char t2[] = "1+f(2)";
#undef I #undef I
#undef f #undef f
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#assert baz(quux) /* { dg-bogus "indented" "^ #ext" } */ #assert baz(quux) /* { dg-bogus "indented" "^ #ext" } */
# assert quux(weeble) /* { dg-bogus "indented" "^ # ext" } */ # assert quux(weeble) /* { dg-bogus "indented" "^ # ext" } */
/* { dg-warning "ISO C does not" "extension warning" { target *-*-* } 22 } */ /* { dg-warning "GCC extension" "extension warning" { target *-*-* } 22 } */
/* { dg-warning "ISO C does not" "extension warning" { target *-*-* } 23 } */ /* { dg-warning "GCC extension" "extension warning" { target *-*-* } 23 } */
/* { dg-warning "ISO C does not" "extension warning" { target *-*-* } 24 } */ /* { dg-warning "GCC extension" "extension warning" { target *-*-* } 24 } */
/* { dg-warning "ISO C does not" "extension warning" { target *-*-* } 25 } */ /* { dg-warning "GCC extension" "extension warning" { target *-*-* } 25 } */
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
#endif #endif
/* { dg-warning "ISO C does not" "extension warning" { target *-*-* } 27 } */ /* { dg-warning "GCC extension" "extension warning" { target *-*-* } 27 } */
/* { dg-warning "ISO C does not" "extension warning" { target *-*-* } 28 } */ /* { dg-warning "GCC extension" "extension warning" { target *-*-* } 28 } */
/* { dg-warning "ISO C does not" "extension warning" { target *-*-* } 29 } */ /* { dg-warning "GCC extension" "extension warning" { target *-*-* } 29 } */
/* { dg-warning "ISO C does not" "extension warning" { target *-*-* } 30 } */ /* { dg-warning "GCC extension" "extension warning" { target *-*-* } 30 } */
...@@ -4,16 +4,16 @@ ...@@ -4,16 +4,16 @@
/* { dg-do preprocess } */ /* { dg-do preprocess } */
/* { dg-options "-Wtraditional -fno-show-column" } */ /* { dg-options "-Wtraditional -fno-show-column" } */
#define foo1(h) sdf "h3" fds "h" /* { dg-warning "macro arg \"h\" would be stringified" "traditional stringification" } */ #define foo1(h) sdf "h3" fds "h" /* { dg-warning "macro argument \"h\" would be stringified" "traditional stringification" } */
#define foo2(h2) sdf "h2" fds "h3" /* { dg-warning "macro arg \"h2\" would be stringified" "traditional stringification" } */ #define foo2(h2) sdf "h2" fds "h3" /* { dg-warning "macro argument \"h2\" would be stringified" "traditional stringification" } */
#define foo3(h3) sdf "h2" fds "h3" /* { dg-warning "macro arg \"h3\" would be stringified" "traditional stringification" } */ #define foo3(h3) sdf "h2" fds "h3" /* { dg-warning "macro argument \"h3\" would be stringified" "traditional stringification" } */
#define foo4(h) sdf 'h3' fds 'h' /* { dg-warning "macro arg \"h\" would be stringified" "traditional stringification" } */ #define foo4(h) sdf 'h3' fds 'h' /* { dg-warning "macro argument \"h\" would be stringified" "traditional stringification" } */
#define foo5(h2) sdf 'h2' fds 'h3' /* { dg-warning "macro arg \"h2\" would be stringified" "traditional stringification" } */ #define foo5(h2) sdf 'h2' fds 'h3' /* { dg-warning "macro argument \"h2\" would be stringified" "traditional stringification" } */
#define foo6(h3) sdf 'h2' fds 'h3' /* { dg-warning "macro arg \"h3\" would be stringified" "traditional stringification" } */ #define foo6(h3) sdf 'h2' fds 'h3' /* { dg-warning "macro argument \"h3\" would be stringified" "traditional stringification" } */
#define foo7(AA, hello, world, EEE) sdf "A B hello C,world,DhelloE F" fds EEE /* { dg-warning "macro arg \"hello\" would be stringified" "traditional stringification" } */ #define foo7(AA, hello, world, EEE) sdf "A B hello C,world,DhelloE F" fds EEE /* { dg-warning "macro argument \"hello\" would be stringified" "traditional stringification" } */
/* Catch the second warning from the above line. */ /* Catch the second warning from the above line. */
/* { dg-warning "macro arg \"world\" would be stringified" "traditional stringification" { target *-*-* } 13 } */ /* { dg-warning "macro argument \"world\" would be stringified" "traditional stringification" { target *-*-* } 13 } */
#line 19 "sys-header.h" 3 #line 19 "sys-header.h" 3
/* We are in system headers now, no -Wtraditional warnings should issue. */ /* We are in system headers now, no -Wtraditional warnings should issue. */
......
...@@ -9,6 +9,6 @@ ...@@ -9,6 +9,6 @@
#define foo(bar) bar #define foo(bar) bar
foo( blah /* { dg-error "unterminated argument" } */ foo( blah /* { dg-error "unterminated" "" { target *-*-* } 13 } */
#undef foo /* { dg-error "may not be used inside" "foo(#undef foo)" } */ #undef foo /* { dg-error "may not be used inside" "foo(#undef foo)" } */
blah ) blah )
/* C99 6.10.8 para 4: None of [the predefined macro names] shall be the /* C99 6.10.8 para 4: None of [the predefined macro names] shall be
subject of a #define or an #undef preprocessing directive. */ the subject of a #define or an #undef preprocessing directive. We
pass -fno-show-column as otherwise dejagnu gets confused. */
/* { dg-do preprocess } */ /* { dg-do preprocess } */
/* { dg-options "-fno-show-column" } */
#undef __DATE__ /* { dg-warning "undefining" "__DATE__" } */ #undef __DATE__ /* { dg-warning "undefining" "__DATE__" } */
#undef __TIME__ /* { dg-warning "undefining" "__TIME__" } */ #undef __TIME__ /* { dg-warning "undefining" "__TIME__" } */
......
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
/* { dg-do preprocess } */ /* { dg-do preprocess } */
#line 1 L"foo" /* { dg-error "not a string" "wide string in #line" } */ #line 1 L"foo" /* { dg-error "not a valid filename" "wide string in #line" } */
#include L"stdio.h" /* { dg-error "expects" "wide string in #include" } */ #include L"stdio.h" /* { dg-error "expects" "wide string in #include" } */
#pragma implementation L"test.h" /* { dg-error "malformed" "wide string in #pragma implementation" } */ #pragma implementation L"test.h" /* { dg-error "malformed" "wide string in #pragma implementation" } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment