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
This commit is contained in:
Neil Booth 2000-10-28 18:01:40 +00:00
parent 93c80368d9
commit 74f215d7e0
21 changed files with 104 additions and 53 deletions

View File

@ -2,5 +2,5 @@
#if 0
#if 0
#endif / /* { dg-error "text after #endif" "text after #endif" } */
#endif / /* { dg-warning "extra tokens" "extra tokens after #endif" } */
#endif

View File

@ -1,18 +1,18 @@
/* More paste corner cases from glibc. */
/* { dg-do run } */
#include <stdlib.h>
#include <string.h>
#define symbol_version(name, version) name##@##version
#define str(x) xstr(x)
#define xstr(x) #x
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 c[] = "getrlimit@GLIBC_2.0";
#include <stdlib.h>
#include <string.h>
int
main(void)
{

View File

@ -2,7 +2,7 @@
/* { dg-options "-pedantic -std=c89" } */
/* 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. */
// C++ comment is not in C89 { dg-bogus "style comment" "bad warning" }

View File

@ -28,8 +28,8 @@ EMPTY #define bar
/* Check that directives always start a line, even if in middle of
macro expansion. */
#define func(x) x
func (2 /* { dg-error "unterminated argument" } */
#define foobar /* { dg-error "may not be used inside" } */
func (2 /* { dg-error "unterminated" "" { target *-*-* } 32 } */
#define foobar /* { dg-error "directives may not" } */
/* For tidiness, I think the directive should still be processed
above. Certainly, continuing to try to find the closing ')' can

View File

@ -4,12 +4,12 @@
/* You can't get away with this in your own code... */
#ifdef KERNEL
#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. */
#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. */
#ifdef KERNEL
#define foo
#endif KERNEL /* { dg-bogus "forbids text after" "bad warning" } */
#endif KERNEL /* { dg-bogus "extra tokens" "bad warning" } */

View File

@ -2,7 +2,7 @@
NUL terminated, so we would print garbage after it. */
/* { 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
#endif
int foo;

View File

@ -2,11 +2,8 @@
Jakub Jelinek <jakub@redhat.com>. */
/* { dg-do preprocess } */
#ifdef 0 /* { dg-error "with invalid argument" } */
#error not seen
#ifdef 0 /* { dg-error "macro names" } */
#endif
#ifndef 0 /* { dg-error "with invalid argument" } */
#else
#error not seen
#ifndef 0 /* { dg-error "macro names" } */
#endif

View File

@ -2,6 +2,8 @@
/* { dg-do preprocess } */
/* Source: Neil Booth. */
/* Various illegal expressions with missing components. */
#if /* { dg-error "no expression" "empty #if" } */

View File

@ -0,0 +1,47 @@
/* { 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);
}

View File

@ -28,13 +28,14 @@
#define foo(, X) /* { dg-error "parameter name" } */
#define foo(X, X) /* { dg-error "duplicate" } */
#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 \
__VA_ARGS__ /* { dg-warning "__VA_ARGS__" } */
#define foo(__VA_ARGS__) /* { dg-warning "__VA_ARGS__" } */
#define foo(...) __VA_ARGS__ /* OK. */
#define goo(__VA_ARGS__) /* { dg-warning "__VA_ARGS__" } */
#define hoo(...) __VA_ARGS__ /* OK. */
#define __VA_ARGS__ /* { dg-warning "__VA_ARGS__" } */
__VA_ARGS__ /* { dg-warning "__VA_ARGS__" } */
/* test # of supplied arguments. */
#define none()
@ -43,12 +44,12 @@ __VA_ARGS__ /* { dg-warning "__VA_ARGS__" } */
#define var0(...)
#define var1(x, ...)
none() /* OK. */
none(ichi) /* { dg-error "too many" } */
none(ichi) /* { dg-error "passed 1" } */
one() /* OK. */
one(ichi) /* OK. */
one(ichi\
, ni) /* { dg-error "too many" } */
two(ichi) /* { dg-error "not enough" } */
, ni) /* { dg-error "passed 2" } */
two(ichi) /* { dg-error "requires 2" } */
var0() /* OK. */
var0(ichi) /* OK. */
var1() /* { dg-warning "rest arguments to be used" } */

View File

@ -56,8 +56,8 @@ int main ()
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))
call to the function glue. */
if (glue (gl, ue) (12) != 12)
err ("Recursive macros");
/* Test placemarker pasting. The glued lines should all appear
@ -106,6 +106,8 @@ int main ()
err ("Various operator pasting");
if (strcmp (hh, "%:%:"))
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)
err ("Pasted numbers");
}

View File

@ -7,6 +7,6 @@
extern int foo(int 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" } */

View File

@ -7,9 +7,9 @@ int foo(int, ...);
a(1)
a(1, 2, 3)
#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)
c(1, 2)
c(1, 2, 3)
#define d(x) foo(##x) /* { dg-warning "nothing can be pasted" } */
d(1)
#define d(x) fo(##x)
d(1) /* { dg-warning "valid preprocessing token" } */

View File

@ -26,5 +26,5 @@
{ dg-warning "previous" "prev def ro" { target *-*-* } 11 }
{ dg-warning "previous" "prev def va" { target *-*-* } 14 }
{ dg-warning "varargs" "named varargs" { target *-*-* } 14 }
{ dg-warning "varargs" "anon varargs" { target *-*-* } 15 } */
{ dg-warning "named variable" "named" { target *-*-* } 14 }
{ dg-warning "anonymous variable" "anon" { target *-*-* } 15 } */

View File

@ -16,7 +16,7 @@ static const char t1[] = "1.1";
#define f h
#define h(a) a+f
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 f

View File

@ -24,7 +24,7 @@
#assert baz(quux) /* { dg-bogus "indented" "^ #ext" } */
# assert quux(weeble) /* { dg-bogus "indented" "^ # ext" } */
/* { dg-warning "ISO C does not" "extension warning" { target *-*-* } 22 } */
/* { dg-warning "ISO C does not" "extension warning" { target *-*-* } 23 } */
/* { dg-warning "ISO C does not" "extension warning" { target *-*-* } 24 } */
/* { dg-warning "ISO C does not" "extension warning" { target *-*-* } 25 } */
/* { dg-warning "GCC extension" "extension warning" { target *-*-* } 22 } */
/* { dg-warning "GCC extension" "extension warning" { target *-*-* } 23 } */
/* { dg-warning "GCC extension" "extension warning" { target *-*-* } 24 } */
/* { dg-warning "GCC extension" "extension warning" { target *-*-* } 25 } */

View File

@ -55,7 +55,7 @@
#endif
/* { dg-warning "ISO C does not" "extension warning" { target *-*-* } 27 } */
/* { dg-warning "ISO C does not" "extension warning" { target *-*-* } 28 } */
/* { dg-warning "ISO C does not" "extension warning" { target *-*-* } 29 } */
/* { dg-warning "ISO C does not" "extension warning" { target *-*-* } 30 } */
/* { dg-warning "GCC extension" "extension warning" { target *-*-* } 27 } */
/* { dg-warning "GCC extension" "extension warning" { target *-*-* } 28 } */
/* { dg-warning "GCC extension" "extension warning" { target *-*-* } 29 } */
/* { dg-warning "GCC extension" "extension warning" { target *-*-* } 30 } */

View File

@ -4,16 +4,16 @@
/* { dg-do preprocess } */
/* { dg-options "-Wtraditional -fno-show-column" } */
#define foo1(h) sdf "h3" fds "h" /* { dg-warning "macro arg \"h\" would be stringified" "traditional stringification" } */
#define foo2(h2) sdf "h2" fds "h3" /* { dg-warning "macro arg \"h2\" would be stringified" "traditional stringification" } */
#define foo3(h3) sdf "h2" fds "h3" /* { dg-warning "macro arg \"h3\" would be stringified" "traditional stringification" } */
#define foo4(h) sdf 'h3' fds 'h' /* { dg-warning "macro arg \"h\" would be stringified" "traditional stringification" } */
#define foo5(h2) sdf 'h2' fds 'h3' /* { dg-warning "macro arg \"h2\" would be stringified" "traditional stringification" } */
#define foo6(h3) sdf 'h2' fds 'h3' /* { dg-warning "macro arg \"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 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 argument \"h2\" 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 argument \"h\" 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 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 argument \"hello\" would be stringified" "traditional stringification" } */
/* 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
/* We are in system headers now, no -Wtraditional warnings should issue. */

View File

@ -9,6 +9,6 @@
#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)" } */
blah )

View File

@ -1,7 +1,9 @@
/* C99 6.10.8 para 4: None of [the predefined macro names] shall be the
subject of a #define or an #undef preprocessing directive. */
/* C99 6.10.8 para 4: None of [the predefined macro names] shall be
the subject of a #define or an #undef preprocessing directive. We
pass -fno-show-column as otherwise dejagnu gets confused. */
/* { dg-do preprocess } */
/* { dg-options "-fno-show-column" } */
#undef __DATE__ /* { dg-warning "undefining" "__DATE__" } */
#undef __TIME__ /* { dg-warning "undefining" "__TIME__" } */

View File

@ -4,6 +4,6 @@
/* { 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" } */
#pragma implementation L"test.h" /* { dg-error "malformed" "wide string in #pragma implementation" } */