+2008-05-13 Tom Tromey <tromey@redhat.com>
+
+ 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 <rguenther@suse.de>
PR middle-end/36227
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
* Include Operation::
* Search Path::
* Once-Only Headers::
+* Alternatives to Wrapper #ifndef::
* Computed Includes::
* Wrapper Headers::
* System Headers::
Obsolete Features
-* Assertions::
-* Obsolete once-only headers::
+* Obsolete Features::
@end detailmenu
@end menu
* Include Operation::
* Search Path::
* Once-Only Headers::
+* Alternatives to Wrapper #ifndef::
* Computed Includes::
* Wrapper Headers::
* System Headers::
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
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
@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
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
-@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.
@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}
-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}
-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
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
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
+2008-05-13 Tom Tromey <tromey@redhat.com>
+
+ 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 <rguenther@suse.de>
PR middle-end/36227
/* Basic tests of the #assert preprocessor extension. */
/* { dg-do compile } */
-/* { dg-options "" } */
+/* { dg-options "-Wno-deprecated" } */
#define def unused expansion
#define fail int fail
/* 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" } */
-/* 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. */
-/* Copyright (C) 2003 Free Software Foundation, Inc.
+/* Copyright (C) 2003, 2006, 2008 Free Software Foundation, Inc.
Test builtin preprocessor assertions.
By Kaveh Ghazi <ghazi@caip.rutgers.edu>. */
/* { dg-do preprocess } */
+/* { dg-options "-ansi -Wno-deprecated" } */
/* Check for #system assertions. */
-/* 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. */
/* { dg-do preprocess } */
-/* { dg-options "" } */ /* shut off -pedantic */
+/* { dg-options "-Wno-deprecated" } */ /* shut off -pedantic */
/* Based on PR 16999 */
/* Test #ident. */
/* { dg-do compile } */
-/* { dg-options "" } */ /* shut off -pedantic */
+/* { dg-options "-Wno-deprecated" } */ /* shut off -pedantic */
#ident "this is an ident"
-/* 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
-/* 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. */
--- /dev/null
+/* 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" } */
--- /dev/null
+/* 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" } */
/* Basic tests of the #assert preprocessor extension. */
/* { dg-do compile } */
-/* { dg-options "" } */
+/* { dg-options "-Wno-deprecated" } */
#define def unused expansion
#define fail int fail
/* 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" } */
-/* 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. */
-/* { 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"
-/* { 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"
-/* { 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"
-/* { 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"
+2008-05-13 Tom Tromey <tromey@redhat.com>
+
+ PR preprocessor/22168:
+ * include/cpplib.h (struct cpp_options) <objc>: 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 <tromey@redhat.com>
PR preprocessor/35313, PR preprocessor/36088:
#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 *);
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 */ \
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
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
}
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;
/* 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.
/* 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. */