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
This commit is contained in:
Zack Weinberg 2000-04-02 22:50:55 +00:00 committed by Zack Weinberg
parent 7c3bb1deec
commit bfab56e7ab
20 changed files with 122 additions and 48 deletions

View file

@ -1,3 +1,24 @@
2000-04-02 Zack Weinberg <zack@wolery.cumb.org>
* 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 <NeilB@earthling.net>
* cppexp.c: New typedef op_t. struct operation and struct

View file

@ -15,7 +15,7 @@ sed 's/^@//' > "include/limits.h" <<'@//E*O*F include/limits.h//'
#ifndef _LIMITS_H
#define _LIMITS_H
#include_next <limits.h>
#include_next <limits.h>
/* 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 <math.h>
#include_next <math.h>
#undef HUGE_VAL
@ -386,7 +386,7 @@ typedef __WCHAR_TYPE__ wchar_t;
#endif /* __WCHAR_T */
#include_next <stddef.h>
#include_next <stddef.h>
#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 <stdlib.h>
#include_next <stdlib.h>
#undef alloca
#else
#include_next <stdlib.h>
#include_next <stdlib.h>
#endif /* _CONVEX_SOURCE */

View file

@ -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
};

View file

@ -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;

View file

@ -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;

View file

@ -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))

View file

@ -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;

View file

@ -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 <float.h>\n");
printf (" #include_next <float.h>\n");
}
#ifdef ID
printf("%sProduced on %s by enquire version %s, CWI, Amsterdam%s\n",

View file

@ -90,7 +90,7 @@ if [ -r $INPUT/$file ]; then
#ifdef __cplusplus
# define exception __math_exception
#endif
#include_next <math.h>
#include_next <math.h>
#ifdef __cplusplus
# undef exception
#endif
@ -123,7 +123,7 @@ if [ -r $INPUT/$file ]; then
#ifdef __cplusplus
# define bool __curses_bool_t
#endif
#include_next <curses.h>
#include_next <curses.h>
#ifdef __cplusplus
# undef bool
#endif

View file

@ -394,7 +394,7 @@ do
#ifdef __cplusplus
# define bool __curses_bool_t
#endif
#include_next <$file>
#include_next <$file>
#ifdef __cplusplus
# undef bool
#endif

View file

@ -57,7 +57,7 @@ if [ -r $INPUT/$file ]; then
#ifdef __cplusplus
# define exception __math_exception
#endif
#include_next <math.h>
#include_next <math.h>
#ifdef __cplusplus
# undef exception
#endif
@ -86,7 +86,7 @@ if [ -r $INPUT/$file ]; then
#ifdef __cplusplus
# define queue __stream_queue
#endif
#include_next <sys/stream.h>
#include_next <sys/stream.h>
#ifdef __cplusplus
# undef queue
#endif
@ -116,7 +116,7 @@ if [ -r $INPUT/$file ]; then
#ifdef __cplusplus
# define bool __curses_bool_t
#endif
#include_next <curses.h>
#include_next <curses.h>
#ifdef __cplusplus
# undef bool
#endif

View file

@ -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 <features.h>\n\
#include_next <asm/posix_types.h>\n\
#include_next <asm/posix_types.h>\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 <features.h>\n\
#include_next <gnu/types.h>\n\
#include_next <gnu/types.h>\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 <features.h>\n\
#include_next <selectbits.h>\n\
#include_next <selectbits.h>\n\
\n\
#if defined(__FD_ZERO) && defined(__GLIBC__) \\\n\
\t&& defined(__GLIBC_MINOR__) && __GLIBC__ == 2 \\\n\

View file

@ -180,7 +180,7 @@ fix = {
for older versions of the Linux kernel. */
\#ifndef _POSIX_TYPES_H_WRAPPER
\#include <features.h>
\#include_next <asm/posix_types.h>
\#include_next <asm/posix_types.h>
\#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 <features.h>
\#include_next <gnu/types.h>
\#include_next <gnu/types.h>
\#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 <features.h>
\#include_next <selectbits.h>
\#include_next <selectbits.h>
\#if defined(__FD_ZERO) && defined(__GLIBC__) \\
&& defined(__GLIBC_MINOR__) && __GLIBC__ == 2 \\

View file

@ -563,7 +563,7 @@ _EOF_
for older versions of the Linux kernel. */
#ifndef _POSIX_TYPES_H_WRAPPER
#include <features.h>
#include_next <asm/posix_types.h>
#include_next <asm/posix_types.h>
#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 <features.h>
#include_next <gnu/types.h>
#include_next <gnu/types.h>
#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 <features.h>
#include_next <selectbits.h>
#include_next <selectbits.h>
#if defined(__FD_ZERO) && defined(__GLIBC__) \
&& defined(__GLIBC_MINOR__) && __GLIBC__ == 2 \

View file

@ -4,5 +4,5 @@
instead of this text. */
#define _GCC_NEXT_LIMITS_H /* tell gcc's limits.h to recurse */
#include_next <limits.h>
#include_next <limits.h>
#undef _GCC_NEXT_LIMITS_H

View file

@ -4,7 +4,7 @@
#else /* not _GCC_LIMITS_H_ */
#ifdef _GCC_NEXT_LIMITS_H
#include_next <limits.h> /* recurse down to the real one */
#include_next <limits.h> /* recurse down to the real one */
#endif
#endif /* not _GCC_LIMITS_H_ */

View file

@ -1,3 +1,12 @@
2000-04-02 Zack Weinberg <zack@wolery.cumb.org>
* 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 <NeilB@earthling.net>
* gcc.dg/cpp-cond.c New tests.

View file

@ -1,4 +1,6 @@
/* Basic tests of the #assert preprocessor extension. */
/* { dg-do compile } */
/* { dg-options "" } */
#define fail int fail

View file

@ -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

View file

@ -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 } */