From bfab56e7ab02ea2616f98cdd1681a5dcc078e189 Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Sun, 2 Apr 2000 22:50:55 +0000 Subject: cppinit.c (cpp_start_read): Turn off -Wtraditional if processing C++. * cppinit.c (cpp_start_read): Turn off -Wtraditional if processing C++. * cpplib.c (_cpp_handle_directive): Improve warnings for traditional C and indented directives. * enquire.c, gsyslimits.h, limity.h, config/convex/fixinc.convex, fixinc/fixinc.irix, fixinc/fixinc.sco, fixinc/fixinc.wrap, fixinc/inclhack.def: Indent the # of #include_next one space. * cp/rtti.c: Un-indent #if and #endif. * cppexp.c (_cpp_parse_expr): If lex returns '#', it's a syntax error, but an error has already been printed. * cpplex.c (_cpp_parse_assertion): Give a more specific error message when called with nothing remaining on the line. (_cpp_lex_token): If _cpp_parse_assertion fails, return an OTHER token, not an ASSERTION. * cpplib.c (do_assert): When we create a 'base' node, clear its aschain pointer. * gcc.c-torture/compile/981211-1.c: Move to... * gcc.dg/cpp-as1.c: ...here. * gcc.dg/cpp-as2.c: New file. * gcc.dg/cpp-tradwarn1.c: Change warning regexps to match the compiler. From-SVN: r32870 --- gcc/ChangeLog | 21 ++++++++++++ gcc/config/convex/fixinc.convex | 10 +++--- gcc/cp/rtti.c | 8 ++--- gcc/cppexp.c | 5 +++ gcc/cppinit.c | 4 +++ gcc/cpplex.c | 12 +++++-- gcc/cpplib.c | 9 ++++-- gcc/enquire.c | 2 +- gcc/fixinc/fixinc.irix | 4 +-- gcc/fixinc/fixinc.sco | 2 +- gcc/fixinc/fixinc.wrap | 6 ++-- gcc/fixinc/fixincl.x | 6 ++-- gcc/fixinc/inclhack.def | 6 ++-- gcc/fixinc/inclhack.sh | 6 ++-- gcc/gsyslimits.h | 2 +- gcc/limity.h | 2 +- gcc/testsuite/ChangeLog | 9 ++++++ gcc/testsuite/gcc.c-torture/compile/981211-1.c | 43 ------------------------ gcc/testsuite/gcc.dg/cpp-as1.c | 45 ++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/cpp-as2.c | 24 ++++++++++++++ gcc/testsuite/gcc.dg/cpp-tradwarn1.c | 30 ++++++++--------- 21 files changed, 165 insertions(+), 91 deletions(-) delete mode 100644 gcc/testsuite/gcc.c-torture/compile/981211-1.c create mode 100644 gcc/testsuite/gcc.dg/cpp-as1.c create mode 100644 gcc/testsuite/gcc.dg/cpp-as2.c (limited to 'gcc') diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 099177c..acb2034 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,24 @@ +2000-04-02 Zack Weinberg + + * cppinit.c (cpp_start_read): Turn off -Wtraditional if + processing C++. + * cpplib.c (_cpp_handle_directive): Improve warnings for + traditional C and indented directives. + + * enquire.c, gsyslimits.h, limity.h, config/convex/fixinc.convex, + fixinc/fixinc.irix, fixinc/fixinc.sco, fixinc/fixinc.wrap, + fixinc/inclhack.def: Indent the # of #include_next one space. + * cp/rtti.c: Un-indent #if and #endif. + + * cppexp.c (_cpp_parse_expr): If lex returns '#', it's a + syntax error, but an error has already been printed. + * cpplex.c (_cpp_parse_assertion): Give a more specific error + message when called with nothing remaining on the line. + (_cpp_lex_token): If _cpp_parse_assertion fails, return an + OTHER token, not an ASSERTION. + * cpplib.c (do_assert): When we create a 'base' node, clear + its aschain pointer. + 2000-04-02 Neil Booth * cppexp.c: New typedef op_t. struct operation and struct diff --git a/gcc/config/convex/fixinc.convex b/gcc/config/convex/fixinc.convex index 0dc5f30..c14dcd4 100644 --- a/gcc/config/convex/fixinc.convex +++ b/gcc/config/convex/fixinc.convex @@ -15,7 +15,7 @@ sed 's/^@//' > "include/limits.h" <<'@//E*O*F include/limits.h//' #ifndef _LIMITS_H #define _LIMITS_H -#include_next + #include_next /* Minimum and maximum values a `char' can hold. */ #ifdef __CHAR_UNSIGNED__ @@ -34,7 +34,7 @@ sed 's/^@//' > "include/math.h" <<'@//E*O*F include/math.h//' #ifndef _MATH_H #define _MATH_H -#include_next + #include_next #undef HUGE_VAL @@ -386,7 +386,7 @@ typedef __WCHAR_TYPE__ wchar_t; #endif /* __WCHAR_T */ -#include_next + #include_next #endif /* _STDDEF_H */ @//E*O*F include/stddef.h// @@ -400,12 +400,12 @@ sed 's/^@//' > "include/stdlib.h" <<'@//E*O*F include/stdlib.h//' #if _CONVEX_SOURCE #define alloca __non_builtin_alloca -#include_next + #include_next #undef alloca #else -#include_next + #include_next #endif /* _CONVEX_SOURCE */ diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c index a91bef8..e9873ba 100644 --- a/gcc/cp/rtti.c +++ b/gcc/cp/rtti.c @@ -1816,9 +1816,9 @@ emit_support_tinfos () &void_type_node, &boolean_type_node, &wchar_type_node, - #if 0 +#if 0 &signed_wchar_type_node, &unsigned_wchar_type_node, - #endif +#endif &char_type_node, &signed_char_type_node, &unsigned_char_type_node, &short_integer_type_node, &short_unsigned_type_node, &integer_type_node, &unsigned_type_node, @@ -1827,11 +1827,11 @@ emit_support_tinfos () &float_type_node, &double_type_node, &long_double_type_node, /* GCC extension types */ - #if 0 +#if 0 &complex_integer_type_node, &complex_float_type_node, &complex_double_type_node, &complex_long_double_type_node, - #endif +#endif 0 }; diff --git a/gcc/cppexp.c b/gcc/cppexp.c index a2c60b7..b89eca8 100644 --- a/gcc/cppexp.c +++ b/gcc/cppexp.c @@ -785,6 +785,11 @@ _cpp_parse_expr (pfile) cpp_ice (pfile, "lex returns a NAME"); case ERROR: goto syntax_error; + case '#': + /* We get '#' when get_directive_token hits a syntactically + invalid assertion predicate. _cpp_parse_assertion has + already issued an error. */ + goto syntax_error; default: cpp_error (pfile, "invalid character in #if"); goto syntax_error; diff --git a/gcc/cppinit.c b/gcc/cppinit.c index 93298ef..62da1f3 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -852,6 +852,10 @@ cpp_start_read (pfile, fname) CPP_OPTION (pfile, trigraphs) = 0; } + /* -Wtraditional is not useful in C++ mode. */ + if (CPP_OPTION (pfile, cplusplus)) + CPP_OPTION (pfile, warn_traditional) = 0; + /* Set this if it hasn't been set already. */ if (user_label_prefix == NULL) user_label_prefix = USER_LABEL_PREFIX; diff --git a/gcc/cpplex.c b/gcc/cpplex.c index b0d3f5f..a57eb8b 100644 --- a/gcc/cpplex.c +++ b/gcc/cpplex.c @@ -604,7 +604,12 @@ _cpp_parse_assertion (pfile) int c, dropwhite; _cpp_skip_hspace (pfile); c = PEEKC(); - if (! is_idstart(c)) + if (c == '\n') + { + cpp_error (pfile, "assertion without predicate"); + return 0; + } + else if (! is_idstart(c)) { cpp_error (pfile, "assertion predicate is not an identifier"); return 0; @@ -709,8 +714,9 @@ _cpp_lex_token (pfile) if (pfile->parsing_if_directive) { _cpp_skip_hspace (pfile); - _cpp_parse_assertion (pfile); - return CPP_ASSERTION; + if (_cpp_parse_assertion (pfile)) + return CPP_ASSERTION; + goto randomchar; } if (pfile->parsing_define_directive && ! CPP_TRADITIONAL (pfile)) diff --git a/gcc/cpplib.c b/gcc/cpplib.c index 747f6f5..2c24de8 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -232,11 +232,11 @@ _cpp_handle_directive (pfile) if (CPP_WTRADITIONAL (pfile)) { if (!hash_at_bol && dtable[i].origin == KANDR) - cpp_warning (pfile, "the # in #%s should be at the left margin", + cpp_warning (pfile, "traditional C ignores #%s with the # indented", dtable[i].name); else if (hash_at_bol && dtable[i].origin != KANDR) cpp_warning (pfile, - "the # in #%s should not be at the left margin", + "traditional C rejects #%s unless the # is indented", dtable[i].name); } @@ -1658,7 +1658,10 @@ do_assert (pfile) bslot = _cpp_lookup_slot (pfile, sym, blen, 1, &bhash); if (! *bslot) - *bslot = base = _cpp_make_hashnode (sym, blen, T_ASSERT, bhash); + { + *bslot = base = _cpp_make_hashnode (sym, blen, T_ASSERT, bhash); + base->value.aschain = 0; + } else { base = *bslot; diff --git a/gcc/enquire.c b/gcc/enquire.c index bb5ea0b..8b4bdda 100644 --- a/gcc/enquire.c +++ b/gcc/enquire.c @@ -716,7 +716,7 @@ int main(argc, argv) int argc; char *argv[]; { printf ("#ifndef _FLOAT_H___\n"); printf ("#define _FLOAT_H___\n"); if (SYS_FLOAT_H_WRAP) - printf ("#include_next \n"); + printf (" #include_next \n"); } #ifdef ID printf("%sProduced on %s by enquire version %s, CWI, Amsterdam%s\n", diff --git a/gcc/fixinc/fixinc.irix b/gcc/fixinc/fixinc.irix index 403c544..3eab1a6 100755 --- a/gcc/fixinc/fixinc.irix +++ b/gcc/fixinc/fixinc.irix @@ -90,7 +90,7 @@ if [ -r $INPUT/$file ]; then #ifdef __cplusplus # define exception __math_exception #endif -#include_next + #include_next #ifdef __cplusplus # undef exception #endif @@ -123,7 +123,7 @@ if [ -r $INPUT/$file ]; then #ifdef __cplusplus # define bool __curses_bool_t #endif -#include_next + #include_next #ifdef __cplusplus # undef bool #endif diff --git a/gcc/fixinc/fixinc.sco b/gcc/fixinc/fixinc.sco index a026a77..77d96e3 100755 --- a/gcc/fixinc/fixinc.sco +++ b/gcc/fixinc/fixinc.sco @@ -394,7 +394,7 @@ do #ifdef __cplusplus # define bool __curses_bool_t #endif -#include_next <$file> + #include_next <$file> #ifdef __cplusplus # undef bool #endif diff --git a/gcc/fixinc/fixinc.wrap b/gcc/fixinc/fixinc.wrap index 0c27536..4631896 100755 --- a/gcc/fixinc/fixinc.wrap +++ b/gcc/fixinc/fixinc.wrap @@ -57,7 +57,7 @@ if [ -r $INPUT/$file ]; then #ifdef __cplusplus # define exception __math_exception #endif -#include_next + #include_next #ifdef __cplusplus # undef exception #endif @@ -86,7 +86,7 @@ if [ -r $INPUT/$file ]; then #ifdef __cplusplus # define queue __stream_queue #endif -#include_next + #include_next #ifdef __cplusplus # undef queue #endif @@ -116,7 +116,7 @@ if [ -r $INPUT/$file ]; then #ifdef __cplusplus # define bool __curses_bool_t #endif -#include_next + #include_next #ifdef __cplusplus # undef bool #endif diff --git a/gcc/fixinc/fixincl.x b/gcc/fixinc/fixincl.x index f120a23..1196ebb 100644 --- a/gcc/fixinc/fixincl.x +++ b/gcc/fixinc/fixincl.x @@ -352,7 +352,7 @@ const char* apzAab_Fd_Zero_Asm_Posix_Types_HPatch[] = { for older versions of the Linux kernel. */\n\ #ifndef _POSIX_TYPES_H_WRAPPER\n\ #include \n\ -#include_next \n\ + #include_next \n\ \n\ #if defined(__FD_ZERO) && !defined(__GLIBC__)\n\ #undef __FD_ZERO\n\ @@ -399,7 +399,7 @@ const char* apzAab_Fd_Zero_Gnu_Types_HPatch[] = { "/* This file fixes a bug in the __FD_ZERO macro present in glibc 1.x. */\n\ #ifndef _TYPES_H_WRAPPER\n\ #include \n\ -#include_next \n\ + #include_next \n\ \n\ #if defined(__FD_ZERO) && !defined(__GLIBC__)\n\ #undef __FD_ZERO\n\ @@ -446,7 +446,7 @@ const char* apzAab_Fd_Zero_Selectbits_HPatch[] = { "/* This file fixes a bug in the __FD_ZERO macro present in glibc 2.0.x. */\n\ #ifndef _SELECTBITS_H_WRAPPER\n\ #include \n\ -#include_next \n\ + #include_next \n\ \n\ #if defined(__FD_ZERO) && defined(__GLIBC__) \\\n\ \t&& defined(__GLIBC_MINOR__) && __GLIBC__ == 2 \\\n\ diff --git a/gcc/fixinc/inclhack.def b/gcc/fixinc/inclhack.def index e431d1f..a49771b 100644 --- a/gcc/fixinc/inclhack.def +++ b/gcc/fixinc/inclhack.def @@ -180,7 +180,7 @@ fix = { for older versions of the Linux kernel. */ \#ifndef _POSIX_TYPES_H_WRAPPER \#include -\#include_next + \#include_next \#if defined(__FD_ZERO) && !defined(__GLIBC__) \#undef __FD_ZERO @@ -219,7 +219,7 @@ fix = { '/* This file fixes a bug in the __FD_ZERO macro present in glibc 1.x. */ \#ifndef _TYPES_H_WRAPPER \#include -\#include_next + \#include_next \#if defined(__FD_ZERO) && !defined(__GLIBC__) \#undef __FD_ZERO @@ -258,7 +258,7 @@ fix = { '/* This file fixes a bug in the __FD_ZERO macro present in glibc 2.0.x. */ \#ifndef _SELECTBITS_H_WRAPPER \#include -\#include_next + \#include_next \#if defined(__FD_ZERO) && defined(__GLIBC__) \\ && defined(__GLIBC_MINOR__) && __GLIBC__ == 2 \\ diff --git a/gcc/fixinc/inclhack.sh b/gcc/fixinc/inclhack.sh index 67a9974..74fc853 100755 --- a/gcc/fixinc/inclhack.sh +++ b/gcc/fixinc/inclhack.sh @@ -563,7 +563,7 @@ _EOF_ for older versions of the Linux kernel. */ #ifndef _POSIX_TYPES_H_WRAPPER #include -#include_next + #include_next #if defined(__FD_ZERO) && !defined(__GLIBC__) #undef __FD_ZERO @@ -600,7 +600,7 @@ _EOF_ /* This file fixes a bug in the __FD_ZERO macro present in glibc 1.x. */ #ifndef _TYPES_H_WRAPPER #include -#include_next + #include_next #if defined(__FD_ZERO) && !defined(__GLIBC__) #undef __FD_ZERO @@ -636,7 +636,7 @@ _EOF_ /* This file fixes a bug in the __FD_ZERO macro present in glibc 2.0.x. */ #ifndef _SELECTBITS_H_WRAPPER #include -#include_next + #include_next #if defined(__FD_ZERO) && defined(__GLIBC__) \ && defined(__GLIBC_MINOR__) && __GLIBC__ == 2 \ diff --git a/gcc/gsyslimits.h b/gcc/gsyslimits.h index a362802..cc7b3fb 100644 --- a/gcc/gsyslimits.h +++ b/gcc/gsyslimits.h @@ -4,5 +4,5 @@ instead of this text. */ #define _GCC_NEXT_LIMITS_H /* tell gcc's limits.h to recurse */ -#include_next + #include_next #undef _GCC_NEXT_LIMITS_H diff --git a/gcc/limity.h b/gcc/limity.h index 8bb398f..b2831fc 100644 --- a/gcc/limity.h +++ b/gcc/limity.h @@ -4,7 +4,7 @@ #else /* not _GCC_LIMITS_H_ */ #ifdef _GCC_NEXT_LIMITS_H -#include_next /* recurse down to the real one */ + #include_next /* recurse down to the real one */ #endif #endif /* not _GCC_LIMITS_H_ */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2bb0cba..f36a7c4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2000-04-02 Zack Weinberg + + * gcc.c-torture/compile/981211-1.c: Move to... + * gcc.dg/cpp-as1.c: ...here. + * gcc.dg/cpp-as2.c: New file. + + * gcc.dg/cpp-tradwarn1.c: Change warning regexps to match the + compiler. + 2000-04-02 Neil Booth * gcc.dg/cpp-cond.c New tests. diff --git a/gcc/testsuite/gcc.c-torture/compile/981211-1.c b/gcc/testsuite/gcc.c-torture/compile/981211-1.c deleted file mode 100644 index 92c9cfb..0000000 --- a/gcc/testsuite/gcc.c-torture/compile/981211-1.c +++ /dev/null @@ -1,43 +0,0 @@ -/* Basic tests of the #assert preprocessor extension. */ - -#define fail int fail - -#assert abc (def) -#assert abc (ghi) -#assert abc (jkl) -#assert space ( s p a c e ) - -/* Basic: */ -#if !#abc (def) || !#abc (ghi) || !#abc (jkl) -fail -#endif - -/* any answer for #abc */ -#if !#abc -fail -#endif - -/* internal whitespace is collapsed, - external whitespace is deleted */ -#if !#space (s p a c e) || !#space ( s p a c e ) || #space (space) -fail -#endif - -/* removing assertions */ -#unassert abc (jkl) -#if !#abc || !#abc (def) || !#abc (ghi) || #abc (jkl) -fail -#endif - -#unassert abc -#if #abc || #abc (def) || #abc (ghi) || #abc (jkl) -fail -#endif - -int gobble - -/* make sure it can succeed too. - also check space before open paren isn't significant */ -#if #space(s p a c e) -; -#endif diff --git a/gcc/testsuite/gcc.dg/cpp-as1.c b/gcc/testsuite/gcc.dg/cpp-as1.c new file mode 100644 index 0000000..6e8c0f8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp-as1.c @@ -0,0 +1,45 @@ +/* Basic tests of the #assert preprocessor extension. */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +#define fail int fail + +#assert abc (def) +#assert abc (ghi) +#assert abc (jkl) +#assert space ( s p a c e ) + +/* Basic: */ +#if !#abc (def) || !#abc (ghi) || !#abc (jkl) +fail +#endif + +/* any answer for #abc */ +#if !#abc +fail +#endif + +/* internal whitespace is collapsed, + external whitespace is deleted */ +#if !#space (s p a c e) || !#space ( s p a c e ) || #space (space) +fail +#endif + +/* removing assertions */ +#unassert abc (jkl) +#if !#abc || !#abc (def) || !#abc (ghi) || #abc (jkl) +fail +#endif + +#unassert abc +#if #abc || #abc (def) || #abc (ghi) || #abc (jkl) +fail +#endif + +int gobble + +/* make sure it can succeed too. + also check space before open paren isn't significant */ +#if #space(s p a c e) +; +#endif diff --git a/gcc/testsuite/gcc.dg/cpp-as2.c b/gcc/testsuite/gcc.dg/cpp-as2.c new file mode 100644 index 0000000..a696270 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp-as2.c @@ -0,0 +1,24 @@ +/* Malformed assertion tests. */ +/* { dg-do preprocess } */ +/* { dg-options "" } */ + +#assert /* { dg-error "without predicate" "assert w/o predicate" } */ +#assert % /* { dg-error "not an identifier" "assert punctuation" } */ +#assert 12 /* { dg-error "not an identifier" "assert number" } */ +#assert abc /* { dg-error "missing token-sequence" "assert w/o answer" } */ + +#if # /* { dg-error "without predicate" "test w/o predicate" } */ +#endif + +#if #% /* { dg-error "not an identifier" "test punctuation" } */ +#endif + +#if #12 /* { dg-error "not an identifier" "test number" } */ +#endif + +#if #abc +#error /* { dg-bogus "error" "test w/o answer" } */ +#endif + +#if #abc[def] /* { dg-error "invalid char" "test with malformed answer" } */ +#endif diff --git a/gcc/testsuite/gcc.dg/cpp-tradwarn1.c b/gcc/testsuite/gcc.dg/cpp-tradwarn1.c index 8395c80..9085ea6 100644 --- a/gcc/testsuite/gcc.dg/cpp-tradwarn1.c +++ b/gcc/testsuite/gcc.dg/cpp-tradwarn1.c @@ -2,27 +2,27 @@ /* { dg-do preprocess } */ /* { dg-options "-pedantic -Wtraditional" } */ -/* Block 1: K+R directives should have the # at the left margin. */ +/* Block 1: K+R directives should have the # indented. */ -#define foo bar /* { dg-bogus "left margin" "^#kandr" } */ -# define foo bar /* { dg-bogus "left margin" "^# kandr" } */ - #define foo bar /* { dg-warning "left margin" "^ #kandr" } */ - # define foo bar /* { dg-warning "left margin" "^ # kandr" } */ +#define foo bar /* { dg-bogus "indented" "^#kandr" } */ +# define foo bar /* { dg-bogus "indented" "^# kandr" } */ + #define foo bar /* { dg-warning "indented" "^ #kandr" } */ + # define foo bar /* { dg-warning "indented" "^ # kandr" } */ -/* Block 2: C89 directives should not have the # at the left margin. */ +/* Block 2: C89 directives should not have the # indented. */ -#pragma whatever /* { dg-warning "left margin" "^#c89" } */ -# pragma whatever /* { dg-warning "left margin" "^# c89" } */ - #pragma whatever /* { dg-bogus "left margin" "^ #c89" } */ - # pragma whatever /* { dg-bogus "left margin" "^ # c89" } */ +#pragma whatever /* { dg-warning "indented" "^#c89" } */ +# pragma whatever /* { dg-warning "indented" "^# c89" } */ + #pragma whatever /* { dg-bogus "indented" "^ #c89" } */ + # pragma whatever /* { dg-bogus "indented" "^ # c89" } */ -/* Block 3: Extensions should not have the # at the left margin, +/* Block 3: Extensions should not have the # indented, _and_ they should get a -pedantic warning. */ -#assert foo(bar) /* { dg-warning "left margin" "^#ext" } */ -# assert bar(baz) /* { dg-warning "left margin" "^# ext" } */ - #assert baz(quux) /* { dg-bogus "left margin" "^ #ext" } */ - # assert quux(weeble) /* { dg-bogus "left margin" "^ # ext" } */ +#assert foo(bar) /* { dg-warning "indented" "^#ext" } */ +# assert bar(baz) /* { dg-warning "indented" "^# ext" } */ + #assert baz(quux) /* { dg-bogus "indented" "^ #ext" } */ + # assert quux(weeble) /* { dg-bogus "indented" "^ # ext" } */ /* { dg-warning "ISO C does not" "extension warning" { target native } 22 } */ /* { dg-warning "ISO C does not" "extension warning" { target native } 23 } */ -- cgit v1.1