From: Tom Tromey Date: Tue, 13 May 2008 14:50:27 +0000 (+0000) Subject: re PR preprocessor/22168 (#if #A == #B should have a diagnostic in ISO C mode) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=899015a064096699065b7349e20e27671f04ba82;p=gcc.git re PR preprocessor/22168 (#if #A == #B should have a diagnostic in ISO C mode) libcpp PR preprocessor/22168: * include/cpplib.h (struct cpp_options) : Update documentation. * expr.c (eval_token): Warn for use of assertions. * directives.c (directive_diagnostics): Warn about extensions. (DEPRECATED): New define. (DIRECTIVE_TABLE): Use it. gcc PR preprocessor/22168: * doc/cpp.texi (Top): Update menu. (Alternatives to Wrapper #ifndef): New node. (Other Directives): Document deprecation. (Obsolete Features): Remove menu. (Assertions): Merge node into Obsolete Features. (Obsolete once-only headers): Move earlier; rename to Alternatives to Wrapper #ifndef. * doc/cppopts.texi: Update. * c.opt (Wdeprecated): Enable for C and ObjC. * doc/invoke.texi (Option Summary): Move -Wno-deprecated. (C++ Dialect Options): Move -Wno-deprecated from here to... (Warning Options): ... here. gcc/testsuite PR preprocessor/22168: * gcc.dg/pch/import-2.hs: Add -Wno-deprecated. * gcc.dg/pch/import-1.hs: Add -Wno-deprecated. * gcc.dg/pch/import-2.c: Add -Wno-deprecated. * gcc.dg/pch/import-1.c: Add -Wno-deprecated. * gcc.dg/cpp/import2.c: Add -Wno-deprecated. * gcc.dg/cpp/import1.c: Add -Wno-deprecated. * gcc.dg/cpp/trad/assert3.c: Add -Wno-deprecated. * gcc.dg/cpp/trad/assert2.c: Add -Wno-deprecated. * gcc.dg/cpp/trad/assert1.c: Add -Wno-deprecated. * gcc.dg/cpp/ident.c: Add -Wno-deprecated. * gcc.dg/cpp/ident-1.c: Add -Wno-deprecated. * gcc.dg/cpp/extratokens.c: Add -Wno-deprecated. * gcc.dg/cpp/assert3.c: Add -Wno-deprecated. * gcc.dg/cpp/assert2.c: Add -Wno-deprecated. * gcc.dg/cpp/assert1.c: Add -Wno-deprecated. * gcc.dg/cpp/assert4.c: Compile with -ansi and not -pedantic. Add -Wno-deprecated. * gcc.dg/cpp/pr22168.c: New file. * gcc.dg/cpp/pr22168-2.c: New file. From-SVN: r135264 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index efb05f229aa..3efb55118a1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,19 @@ +2008-05-13 Tom Tromey + + PR preprocessor/22168: + * doc/cpp.texi (Top): Update menu. + (Alternatives to Wrapper #ifndef): New node. + (Other Directives): Document deprecation. + (Obsolete Features): Remove menu. + (Assertions): Merge node into Obsolete Features. + (Obsolete once-only headers): Move earlier; rename to Alternatives + to Wrapper #ifndef. + * doc/cppopts.texi: Update. + * c.opt (Wdeprecated): Enable for C and ObjC. + * doc/invoke.texi (Option Summary): Move -Wno-deprecated. + (C++ Dialect Options): Move -Wno-deprecated from here to... + (Warning Options): ... here. + 2008-05-13 Richard Guenther PR middle-end/36227 diff --git a/gcc/c.opt b/gcc/c.opt index dd9013e1c37..09d5187bd2f 100644 --- a/gcc/c.opt +++ b/gcc/c.opt @@ -176,7 +176,7 @@ C ObjC Var(warn_declaration_after_statement) Warning Warn when a declaration is found after a statement Wdeprecated -C++ ObjC++ Var(warn_deprecated) Init(1) Warning +C C++ ObjC ObjC++ Var(warn_deprecated) Init(1) Warning Warn about deprecated compiler features Wdiv-by-zero diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi index b98aef2bd68..9e2f19ad0b5 100644 --- a/gcc/doc/cpp.texi +++ b/gcc/doc/cpp.texi @@ -111,6 +111,7 @@ Header Files * Include Operation:: * Search Path:: * Once-Only Headers:: +* Alternatives to Wrapper #ifndef:: * Computed Includes:: * Wrapper Headers:: * System Headers:: @@ -168,8 +169,7 @@ Implementation Details Obsolete Features -* Assertions:: -* Obsolete once-only headers:: +* Obsolete Features:: @end detailmenu @end menu @@ -734,6 +734,7 @@ underscores in header file names, and at most one dot. * Include Operation:: * Search Path:: * Once-Only Headers:: +* Alternatives to Wrapper #ifndef:: * Computed Includes:: * Wrapper Headers:: * System Headers:: @@ -959,6 +960,42 @@ begin with @samp{_}. In a system header file, it should begin with file, the macro name should contain the name of the file and some additional text, to avoid conflicts with other header files. +@node Alternatives to Wrapper #ifndef +@section Alternatives to Wrapper #ifndef + +CPP supports two more ways of indicating that a header file should be +read only once. Neither one is as portable as a wrapper @samp{#ifndef} +and we recommend you do not use them in new programs, with the caveat +that @samp{#import} is standard practice in Objective-C. + +@findex #import +CPP supports a variant of @samp{#include} called @samp{#import} which +includes a file, but does so at most once. If you use @samp{#import} +instead of @samp{#include}, then you don't need the conditionals +inside the header file to prevent multiple inclusion of the contents. +@samp{#import} is standard in Objective-C, but is considered a +deprecated extension in C and C++. + +@samp{#import} is not a well designed feature. It requires the users of +a header file to know that it should only be included once. It is much +better for the header file's implementor to write the file so that users +don't need to know this. Using a wrapper @samp{#ifndef} accomplishes +this goal. + +In the present implementation, a single use of @samp{#import} will +prevent the file from ever being read again, by either @samp{#import} or +@samp{#include}. You should not rely on this; do not use both +@samp{#import} and @samp{#include} to refer to the same header file. + +Another way to prevent a header file from being included more than once +is with the @samp{#pragma once} directive. If @samp{#pragma once} is +seen when scanning a header file, that file will never be read again, no +matter what. + +@samp{#pragma once} does not have the problems that @samp{#import} does, +but it is not recognized by all preprocessors, so you cannot rely on it +in a portable program. + @node Computed Includes @section Computed Includes @cindex computed includes @@ -3467,6 +3504,8 @@ These directives are not part of the C standard, but they are not official GNU extensions either. What historical information we have been able to find, suggests they originated with System V@. +Both @samp{#ident} and @samp{#sccs} are deprecated extensions. + @cindex null directive The @dfn{null directive} consists of a @samp{#} followed by a newline, with only whitespace (including comments) in between. A null directive @@ -4004,16 +4043,10 @@ may not be a limitation. @node Obsolete Features @section Obsolete Features -CPP has a number of features which are present mainly for -compatibility with older programs. We discourage their use in new code. -In some cases, we plan to remove the feature in a future version of GCC@. +CPP has some features which are present mainly for compatibility with +older programs. We discourage their use in new code. In some cases, +we plan to remove the feature in a future version of GCC@. -@menu -* Assertions:: -* Obsolete once-only headers:: -@end menu - -@node Assertions @subsection Assertions @cindex assertions @@ -4097,42 +4130,6 @@ no effect. You can also make or cancel assertions using command line options. @xref{Invocation}. -@node Obsolete once-only headers -@subsection Obsolete once-only headers - -CPP supports two more ways of indicating that a header file should be -read only once. Neither one is as portable as a wrapper @samp{#ifndef}, -and we recommend you do not use them in new programs. - -@findex #import -In the Objective-C language, there is a variant of @samp{#include} -called @samp{#import} which includes a file, but does so at most once. -If you use @samp{#import} instead of @samp{#include}, then you don't -need the conditionals inside the header file to prevent multiple -inclusion of the contents. GCC permits the use of @samp{#import} in C -and C++ as well as Objective-C@. However, it is not in standard C or C++ -and should therefore not be used by portable programs. - -@samp{#import} is not a well designed feature. It requires the users of -a header file to know that it should only be included once. It is much -better for the header file's implementor to write the file so that users -don't need to know this. Using a wrapper @samp{#ifndef} accomplishes -this goal. - -In the present implementation, a single use of @samp{#import} will -prevent the file from ever being read again, by either @samp{#import} or -@samp{#include}. You should not rely on this; do not use both -@samp{#import} and @samp{#include} to refer to the same header file. - -Another way to prevent a header file from being included more than once -is with the @samp{#pragma once} directive. If @samp{#pragma once} is -seen when scanning a header file, that file will never be read again, no -matter what. - -@samp{#pragma once} does not have the problems that @samp{#import} does, -but it is not recognized by all preprocessors, so you cannot rely on it -in a portable program. - @node Differences from previous versions @section Differences from previous versions @cindex differences from previous versions diff --git a/gcc/doc/cppopts.texi b/gcc/doc/cppopts.texi index 4b02a87cb8e..0cdfa1b2f9a 100644 --- a/gcc/doc/cppopts.texi +++ b/gcc/doc/cppopts.texi @@ -1,4 +1,4 @@ -@c Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 +@c Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 @c Free Software Foundation, Inc. @c This is part of the CPP and GCC manuals. @c For copying conditions, see the file gcc.texi. @@ -633,7 +633,7 @@ Make an assertion with the predicate @var{predicate} and answer @var{predicate}(@var{answer})}, which is still supported, because it does not use shell special characters. @ifset cppmanual -@xref{Assertions}. +@xref{Obsolete Features}. @end ifset @item -A -@var{predicate}=@var{answer} diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index e898148611a..a7704a08323 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -195,7 +195,7 @@ in the following sections. -fvisibility-ms-compat @gol -Wabi -Wctor-dtor-privacy @gol -Wnon-virtual-dtor -Wreorder @gol --Weffc++ -Wno-deprecated -Wstrict-null-sentinel @gol +-Weffc++ -Wstrict-null-sentinel @gol -Wno-non-template-friend -Wold-style-cast @gol -Woverloaded-virtual -Wno-pmf-conversions @gol -Wsign-promo} @@ -230,8 +230,8 @@ Objective-C and Objective-C++ Dialects}. -w -Wextra -Wall -Waddress -Waggregate-return -Warray-bounds @gol -Wno-attributes -Wc++-compat -Wc++0x-compat -Wcast-align -Wcast-qual @gol -Wchar-subscripts -Wclobbered -Wcomment @gol --Wconversion -Wcoverage-mismatch -Wno-deprecated-declarations @gol --Wdisabled-optimization -Wno-div-by-zero @gol +-Wconversion -Wcoverage-mismatch -Wno-deprecated @gol +-Wno-deprecated-declarations -Wdisabled-optimization -Wno-div-by-zero @gol -Wempty-body -Wno-endif-labels @gol -Werror -Werror=* @gol -Wfatal-errors -Wfloat-equal -Wformat -Wformat=2 @gol @@ -2119,11 +2119,6 @@ When selecting this option, be aware that the standard library headers do not obey all of these guidelines; use @samp{grep -v} to filter out those warnings. -@item -Wno-deprecated @r{(C++ and Objective-C++ only)} -@opindex Wno-deprecated -@opindex Wdeprecated -Do not warn about usage of deprecated features. @xref{Deprecated Features}. - @item -Wstrict-null-sentinel @r{(C++ and Objective-C++ only)} @opindex Wstrict-null-sentinel @opindex Wno-strict-null-sentinel @@ -3885,6 +3880,11 @@ confused with the digit 0, and so is not the default, but may be useful as a local coding convention if the programming environment is unable to be fixed to display these characters distinctly. +@item -Wno-deprecated +@opindex Wno-deprecated +@opindex Wdeprecated +Do not warn about usage of deprecated features. @xref{Deprecated Features}. + @item -Wno-deprecated-declarations @opindex Wno-deprecated-declarations @opindex Wdeprecated-declarations diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 199a80ea711..ff46688d18e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,26 @@ +2008-05-13 Tom Tromey + + PR preprocessor/22168: + * gcc.dg/pch/import-2.hs: Add -Wno-deprecated. + * gcc.dg/pch/import-1.hs: Add -Wno-deprecated. + * gcc.dg/pch/import-2.c: Add -Wno-deprecated. + * gcc.dg/pch/import-1.c: Add -Wno-deprecated. + * gcc.dg/cpp/import2.c: Add -Wno-deprecated. + * gcc.dg/cpp/import1.c: Add -Wno-deprecated. + * gcc.dg/cpp/trad/assert3.c: Add -Wno-deprecated. + * gcc.dg/cpp/trad/assert2.c: Add -Wno-deprecated. + * gcc.dg/cpp/trad/assert1.c: Add -Wno-deprecated. + * gcc.dg/cpp/ident.c: Add -Wno-deprecated. + * gcc.dg/cpp/ident-1.c: Add -Wno-deprecated. + * gcc.dg/cpp/extratokens.c: Add -Wno-deprecated. + * gcc.dg/cpp/assert3.c: Add -Wno-deprecated. + * gcc.dg/cpp/assert2.c: Add -Wno-deprecated. + * gcc.dg/cpp/assert1.c: Add -Wno-deprecated. + * gcc.dg/cpp/assert4.c: Compile with -ansi and not -pedantic. Add + -Wno-deprecated. + * gcc.dg/cpp/pr22168.c: New file. + * gcc.dg/cpp/pr22168-2.c: New file. + 2008-05-13 Richard Guenther PR middle-end/36227 diff --git a/gcc/testsuite/gcc.dg/cpp/assert1.c b/gcc/testsuite/gcc.dg/cpp/assert1.c index ff7cc620bec..d1446105c54 100644 --- a/gcc/testsuite/gcc.dg/cpp/assert1.c +++ b/gcc/testsuite/gcc.dg/cpp/assert1.c @@ -1,6 +1,6 @@ /* Basic tests of the #assert preprocessor extension. */ /* { dg-do compile } */ -/* { dg-options "" } */ +/* { dg-options "-Wno-deprecated" } */ #define def unused expansion #define fail int fail diff --git a/gcc/testsuite/gcc.dg/cpp/assert2.c b/gcc/testsuite/gcc.dg/cpp/assert2.c index bdbf85d2998..130f7f5320a 100644 --- a/gcc/testsuite/gcc.dg/cpp/assert2.c +++ b/gcc/testsuite/gcc.dg/cpp/assert2.c @@ -1,6 +1,6 @@ /* Malformed assertion tests. */ /* { dg-do preprocess } */ -/* { dg-options "-fno-show-column" } */ +/* { dg-options "-fno-show-column -Wno-deprecated" } */ #assert /* { dg-error "without predicate" "assert w/o predicate" } */ #assert % /* { dg-error "an identifier" "assert punctuation" } */ diff --git a/gcc/testsuite/gcc.dg/cpp/assert3.c b/gcc/testsuite/gcc.dg/cpp/assert3.c index df9b19fdaf9..9010ecebd4e 100644 --- a/gcc/testsuite/gcc.dg/cpp/assert3.c +++ b/gcc/testsuite/gcc.dg/cpp/assert3.c @@ -1,7 +1,7 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. */ +/* Copyright (C) 2000, 2008 Free Software Foundation, Inc. */ /* { dg-do preprocess } */ -/* { dg-options "-A abc=def -A abc\(ghi\) \"-Aabc = jkl\" -A abc=mno -A -abc=mno" } */ +/* { dg-options "-A abc=def -A abc\(ghi\) \"-Aabc = jkl\" -A abc=mno -A -abc=mno -Wno-deprecated" } */ /* Test -A command line syntax. Source Neil Booth. 31 Oct 2000. */ diff --git a/gcc/testsuite/gcc.dg/cpp/assert4.c b/gcc/testsuite/gcc.dg/cpp/assert4.c index f03d89fbadf..c43ba2fae96 100644 --- a/gcc/testsuite/gcc.dg/cpp/assert4.c +++ b/gcc/testsuite/gcc.dg/cpp/assert4.c @@ -1,8 +1,9 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. +/* Copyright (C) 2003, 2006, 2008 Free Software Foundation, Inc. Test builtin preprocessor assertions. By Kaveh Ghazi . */ /* { dg-do preprocess } */ +/* { dg-options "-ansi -Wno-deprecated" } */ /* Check for #system assertions. */ diff --git a/gcc/testsuite/gcc.dg/cpp/extratokens.c b/gcc/testsuite/gcc.dg/cpp/extratokens.c index ffbe7df3c51..d3e941bfff0 100644 --- a/gcc/testsuite/gcc.dg/cpp/extratokens.c +++ b/gcc/testsuite/gcc.dg/cpp/extratokens.c @@ -1,7 +1,7 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. */ +/* Copyright (C) 2000, 2008 Free Software Foundation, Inc. */ /* { dg-do preprocess } */ -/* { dg-options "-fno-show-column" } */ +/* { dg-options "-fno-show-column -Wno-deprecated" } */ /* Tests all directives that do not permit excess tokens at the end of the line. */ diff --git a/gcc/testsuite/gcc.dg/cpp/ident-1.c b/gcc/testsuite/gcc.dg/cpp/ident-1.c index cb6c0dcf658..da6e516d2f0 100644 --- a/gcc/testsuite/gcc.dg/cpp/ident-1.c +++ b/gcc/testsuite/gcc.dg/cpp/ident-1.c @@ -1,5 +1,5 @@ /* { dg-do preprocess } */ -/* { dg-options "" } */ /* shut off -pedantic */ +/* { dg-options "-Wno-deprecated" } */ /* shut off -pedantic */ /* Based on PR 16999 */ diff --git a/gcc/testsuite/gcc.dg/cpp/ident.c b/gcc/testsuite/gcc.dg/cpp/ident.c index 3820f4b43ad..5477cbe1067 100644 --- a/gcc/testsuite/gcc.dg/cpp/ident.c +++ b/gcc/testsuite/gcc.dg/cpp/ident.c @@ -1,6 +1,6 @@ /* Test #ident. */ /* { dg-do compile } */ -/* { dg-options "" } */ /* shut off -pedantic */ +/* { dg-options "-Wno-deprecated" } */ /* shut off -pedantic */ #ident "this is an ident" diff --git a/gcc/testsuite/gcc.dg/cpp/import1.c b/gcc/testsuite/gcc.dg/cpp/import1.c index d118d7fb051..07130f014c1 100644 --- a/gcc/testsuite/gcc.dg/cpp/import1.c +++ b/gcc/testsuite/gcc.dg/cpp/import1.c @@ -1,7 +1,7 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. */ +/* Copyright (C) 2003, 2008 Free Software Foundation, Inc. */ /* { dg-do preprocess } */ -/* { dg-options "" } */ +/* { dg-options "-Wno-deprecated" } */ /* This tests that our eagerness to apply the multiple include guard optimization to the #import doesn't stop us marking the file diff --git a/gcc/testsuite/gcc.dg/cpp/import2.c b/gcc/testsuite/gcc.dg/cpp/import2.c index 5c32523880e..99b987551b3 100644 --- a/gcc/testsuite/gcc.dg/cpp/import2.c +++ b/gcc/testsuite/gcc.dg/cpp/import2.c @@ -1,7 +1,7 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. */ +/* Copyright (C) 2003, 2008 Free Software Foundation, Inc. */ /* { dg-do preprocess } */ -/* { dg-options "" } */ +/* { dg-options "-Wno-deprecated" } */ /* This tests that the file is only included once Neil Booth, 2 August 2003. */ diff --git a/gcc/testsuite/gcc.dg/cpp/pr22168-2.c b/gcc/testsuite/gcc.dg/cpp/pr22168-2.c new file mode 100644 index 00000000000..c1e308dfcd8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/pr22168-2.c @@ -0,0 +1,12 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. */ +/* PR preprocessor/22168 */ + +/* { dg-do preprocess } + { dg-options -Wdeprecated } */ +#if #foo(bar) /* { dg-warning "deprecated" } */ +int x; +#else +int y; +#endif +#assert zzz(a) /* { dg-warning "deprecated" } */ +#unassert yyy /* { dg-warning "deprecated" } */ diff --git a/gcc/testsuite/gcc.dg/cpp/pr22168.c b/gcc/testsuite/gcc.dg/cpp/pr22168.c new file mode 100644 index 00000000000..fecb972f766 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/pr22168.c @@ -0,0 +1,12 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. */ +/* PR preprocessor/22168 */ + +/* { dg-do preprocess } + { dg-options -pedantic } */ +#if #foo(bar) /* { dg-warning "GCC extension" } */ +int x; +#else +int y; +#endif +#assert zzz(a) /* { dg-warning "GCC extension" } */ +#unassert yyy /* { dg-warning "GCC extension" } */ diff --git a/gcc/testsuite/gcc.dg/cpp/trad/assert1.c b/gcc/testsuite/gcc.dg/cpp/trad/assert1.c index ff7cc620bec..d1446105c54 100644 --- a/gcc/testsuite/gcc.dg/cpp/trad/assert1.c +++ b/gcc/testsuite/gcc.dg/cpp/trad/assert1.c @@ -1,6 +1,6 @@ /* Basic tests of the #assert preprocessor extension. */ /* { dg-do compile } */ -/* { dg-options "" } */ +/* { dg-options "-Wno-deprecated" } */ #define def unused expansion #define fail int fail diff --git a/gcc/testsuite/gcc.dg/cpp/trad/assert2.c b/gcc/testsuite/gcc.dg/cpp/trad/assert2.c index 9838e149cbf..4aa0b994479 100644 --- a/gcc/testsuite/gcc.dg/cpp/trad/assert2.c +++ b/gcc/testsuite/gcc.dg/cpp/trad/assert2.c @@ -1,5 +1,6 @@ /* Malformed assertion tests. */ /* { dg-do preprocess } */ +/* { dg-options "-Wno-deprecated" } */ #assert /* { dg-error "without predicate" "assert w/o predicate" } */ #assert % /* { dg-error "an identifier" "assert punctuation" } */ diff --git a/gcc/testsuite/gcc.dg/cpp/trad/assert3.c b/gcc/testsuite/gcc.dg/cpp/trad/assert3.c index df9b19fdaf9..9010ecebd4e 100644 --- a/gcc/testsuite/gcc.dg/cpp/trad/assert3.c +++ b/gcc/testsuite/gcc.dg/cpp/trad/assert3.c @@ -1,7 +1,7 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. */ +/* Copyright (C) 2000, 2008 Free Software Foundation, Inc. */ /* { dg-do preprocess } */ -/* { dg-options "-A abc=def -A abc\(ghi\) \"-Aabc = jkl\" -A abc=mno -A -abc=mno" } */ +/* { dg-options "-A abc=def -A abc\(ghi\) \"-Aabc = jkl\" -A abc=mno -A -abc=mno -Wno-deprecated" } */ /* Test -A command line syntax. Source Neil Booth. 31 Oct 2000. */ diff --git a/gcc/testsuite/gcc.dg/pch/import-1.c b/gcc/testsuite/gcc.dg/pch/import-1.c index 09460af057e..b036217f82b 100644 --- a/gcc/testsuite/gcc.dg/pch/import-1.c +++ b/gcc/testsuite/gcc.dg/pch/import-1.c @@ -1,4 +1,4 @@ -/* { dg-options "-I. -I $srcdir/gcc.dg/pch" } */ +/* { dg-options "-I. -I $srcdir/gcc.dg/pch -Wno-deprecated" } */ #include "import-1.h" #include "import-1a.h" #import "import-1b.h" diff --git a/gcc/testsuite/gcc.dg/pch/import-1.hs b/gcc/testsuite/gcc.dg/pch/import-1.hs index 87d9ed92bea..a59099d44d4 100644 --- a/gcc/testsuite/gcc.dg/pch/import-1.hs +++ b/gcc/testsuite/gcc.dg/pch/import-1.hs @@ -1,4 +1,4 @@ -/* { dg-options "-I. -I $srcdir/gcc.dg/pch" } */ +/* { dg-options "-I. -I $srcdir/gcc.dg/pch -Wno-deprecated" } */ #import "import-1a.h" #include "import-1b.h" #include "import-1c.h" diff --git a/gcc/testsuite/gcc.dg/pch/import-2.c b/gcc/testsuite/gcc.dg/pch/import-2.c index f9535688182..c037e3d1f6f 100644 --- a/gcc/testsuite/gcc.dg/pch/import-2.c +++ b/gcc/testsuite/gcc.dg/pch/import-2.c @@ -1,4 +1,4 @@ -/* { dg-options "-I. -I $srcdir/gcc.dg/pch/include" } */ +/* { dg-options "-I. -I $srcdir/gcc.dg/pch/include -Wno-deprecated" } */ #include "import-2.h" #import "import-2b.h" diff --git a/gcc/testsuite/gcc.dg/pch/import-2.hs b/gcc/testsuite/gcc.dg/pch/import-2.hs index f9798c12266..8a725de14a2 100644 --- a/gcc/testsuite/gcc.dg/pch/import-2.hs +++ b/gcc/testsuite/gcc.dg/pch/import-2.hs @@ -1,4 +1,4 @@ -/* { dg-options "-I $srcdir/gcc.dg/pch/include" } */ +/* { dg-options "-I $srcdir/gcc.dg/pch/include -Wno-deprecated" } */ #import "import-2b.h" #import "import-2a.h" diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index b86e22e613d..fc226b452bb 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,13 @@ +2008-05-13 Tom Tromey + + PR preprocessor/22168: + * include/cpplib.h (struct cpp_options) : Update + documentation. + * expr.c (eval_token): Warn for use of assertions. + * directives.c (directive_diagnostics): Warn about extensions. + (DEPRECATED): New define. + (DIRECTIVE_TABLE): Use it. + 2008-05-06 Tom Tromey PR preprocessor/35313, PR preprocessor/36088: diff --git a/libcpp/directives.c b/libcpp/directives.c index bac08ad2f46..9954796b36a 100644 --- a/libcpp/directives.c +++ b/libcpp/directives.c @@ -75,6 +75,7 @@ struct pragma_entry #define INCL (1 << 2) #define IN_I (1 << 3) #define EXPAND (1 << 4) +#define DEPRECATED (1 << 5) /* Defines one #-directive, including how to handle it. */ typedef void (*directive_handler) (cpp_reader *); @@ -130,9 +131,9 @@ static void handle_assertion (cpp_reader *, const char *, int); counts from all the source code I have lying around (egcs and libc CVS as of 1999-05-18, plus grub-0.5.91, linux-2.2.9, and pcmcia-cs-3.0.9). This is no longer important as directive lookup - is now O(1). All extensions other than #warning and #include_next - are deprecated. The name is where the extension appears to have - come from. */ + is now O(1). All extensions other than #warning, #include_next, + and #import are deprecated. The name is where the extension + appears to have come from. */ #define DIRECTIVE_TABLE \ D(define, T_DEFINE = 0, KANDR, IN_I) /* 270554 */ \ @@ -149,11 +150,11 @@ D(error, T_ERROR, STDC89, 0) /* 475 */ \ D(pragma, T_PRAGMA, STDC89, IN_I) /* 195 */ \ D(warning, T_WARNING, EXTENSION, 0) /* 22 */ \ D(include_next, T_INCLUDE_NEXT, EXTENSION, INCL | EXPAND) /* 19 */ \ -D(ident, T_IDENT, EXTENSION, IN_I) /* 11 */ \ +D(ident, T_IDENT, EXTENSION, IN_I | DEPRECATED) /* 11 */ \ D(import, T_IMPORT, EXTENSION, INCL | EXPAND) /* 0 ObjC */ \ -D(assert, T_ASSERT, EXTENSION, 0) /* 0 SVR4 */ \ -D(unassert, T_UNASSERT, EXTENSION, 0) /* 0 SVR4 */ \ -D(sccs, T_SCCS, EXTENSION, IN_I) /* 0 SVR4? */ +D(assert, T_ASSERT, EXTENSION, DEPRECATED) /* 0 SVR4 */ \ +D(unassert, T_UNASSERT, EXTENSION, DEPRECATED) /* 0 SVR4 */ \ +D(sccs, T_SCCS, EXTENSION, IN_I | DEPRECATED) /* 0 SVR4? */ /* #sccs is synonymous with #ident. */ #define do_sccs do_ident @@ -337,11 +338,20 @@ prepare_directive_trad (cpp_reader *pfile) static void directive_diagnostics (cpp_reader *pfile, const directive *dir, int indented) { - /* Issue -pedantic warnings for extensions. */ - if (CPP_PEDANTIC (pfile) - && ! pfile->state.skipping - && dir->origin == EXTENSION) - cpp_error (pfile, CPP_DL_PEDWARN, "#%s is a GCC extension", dir->name); + /* Issue -pedantic or deprecated warnings for extensions. We let + -pedantic take precedence if both are applicable. */ + if (! pfile->state.skipping) + { + if (dir->origin == EXTENSION + && !(dir == &dtable[T_IMPORT] && CPP_OPTION (pfile, objc)) + && CPP_PEDANTIC (pfile)) + cpp_error (pfile, CPP_DL_PEDWARN, "#%s is a GCC extension", dir->name); + else if (((dir->flags & DEPRECATED) != 0 + || (dir == &dtable[T_IMPORT] && !CPP_OPTION (pfile, objc))) + && CPP_OPTION (pfile, warn_deprecated)) + cpp_error (pfile, CPP_DL_WARNING, "#%s is a deprecated GCC extension", + dir->name); + } /* Traditionally, a directive is ignored unless its # is in column 1. Therefore in code intended to work with K+R diff --git a/libcpp/expr.c b/libcpp/expr.c index af0e2590ee4..2e52617a656 100644 --- a/libcpp/expr.c +++ b/libcpp/expr.c @@ -745,10 +745,25 @@ eval_token (cpp_reader *pfile, const cpp_token *token) } break; - default: /* CPP_HASH */ + case CPP_HASH: + if (!pfile->state.skipping) + { + /* A pedantic warning takes precedence over a deprecated + warning here. */ + if (CPP_PEDANTIC (pfile)) + cpp_error (pfile, CPP_DL_PEDWARN, + "assertions are a GCC extension"); + else if (CPP_OPTION (pfile, warn_deprecated)) + cpp_error (pfile, CPP_DL_WARNING, + "assertions are a deprecated extension"); + } _cpp_test_assertion (pfile, &temp); result.high = 0; result.low = temp; + break; + + default: + abort (); } result.unsignedp = !!unsignedp; diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 46ab14603ed..6b3f7615c57 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -1,6 +1,6 @@ /* Definitions for CPP library. Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, - 2004, 2005, 2007 + 2004, 2005, 2007, 2008 Free Software Foundation, Inc. Written by Per Bothner, 1994-95. @@ -275,8 +275,9 @@ struct cpp_options /* Nonzero means handle cplusplus style comments. */ unsigned char cplusplus_comments; - /* Nonzero means define __OBJC__, treat @ as a special token, and - use the OBJC[PLUS]_INCLUDE_PATH environment variable. */ + /* Nonzero means define __OBJC__, treat @ as a special token, use + the OBJC[PLUS]_INCLUDE_PATH environment variable, and allow + "#import". */ unsigned char objc; /* Nonzero means don't copy comments into the output file. */