This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: #import, #pragma once to be removed in 3.4
- From: Zack Weinberg <zack at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 06 Feb 2003 13:12:34 -0800
- Subject: Re: #import, #pragma once to be removed in 3.4
- References: <87lm0tjfsg.fsf@egil.codesourcery.com>
Zack Weinberg <zack@codesourcery.com> writes:
> Accordingly: #import and #pragma once will be removed from FSF GCC in
> 3.4. I will shortly send a patch to gcc-patches to implement that.
Here is the patch; it's undergoing bootstrap now. I will wait until
Monday to apply it, to give time for objections.
Geoff, I would appreciate it if you could contribute a paragraph to
the manual about the problems of PCH interaction with #import, since
that is the proximate cause of the removal.
zw
* cpplib.c (do_pragma_once, do_import): Delete.
(DIRECTIVE_TABLE): Remove #import entry.
(do_include_common): Remove code handling IT_IMPORT. Move
special check for IT_INCLUDE_NEXT...
(do_include_next): ... here.
(_cpp_init_internal_pragmas): Don't register #pragma once.
* cppfiles.c (_cpp_never_reread): Delete.
(stack_include_file): Set inc->cmacro = NEVER_REREAD directly.
(_cpp_execute_include): Delete code handling IT_IMPORT.
* cpphash.h (enum include_type): Delete IT_IMPORT.
(_cpp_never_reread): Delete prototype.
* cpplib.c (struct cpp_options): Delete warn_import.
* cppinit.c (cpp_create_reader): Don't set warn_import.
* c-opts.c: Remove all mention of -Wimport and -Wno-import.
* toplev.c: Likewise.
* objc/objc-act.c: Adjust error message.
* doc/cpp.texi: Delete node 'Obsolete once-only headers'.
Add text to node 'Differences from previous versions'
explaining #import and #pragma once and why they were removed.
===================================================================
Index: c-opts.c
--- c-opts.c 28 Jan 2003 19:29:57 -0000 1.28
+++ c-opts.c 6 Feb 2003 20:59:54 -0000
@@ -154,7 +154,6 @@ static void sanitize_cpp_opts PARAMS ((v
OPT("Wimplicit", CL_ALL, OPT_Wimplicit) \
OPT("Wimplicit-function-declaration", CL_C, OPT_Wimplicit_function_decl) \
OPT("Wimplicit-int", CL_C, OPT_Wimplicit_int) \
- OPT("Wimport", CL_ALL, OPT_Wimport) \
OPT("Winvalid-pch", CL_ALL, OPT_Winvalid_pch) \
OPT("Wlong-long", CL_ALL, OPT_Wlong_long) \
OPT("Wmain", CL_C, OPT_Wmain) \
@@ -837,10 +836,6 @@ c_common_decode_option (argc, argv)
warn_implicit_int = on;
break;
- case OPT_Wimport:
- cpp_opts->warn_import = on;
- break;
-
case OPT_Winvalid_pch:
cpp_opts->warn_invalid_pch = on;
break;
@@ -1760,7 +1755,6 @@ Switches:\n\
fputs (_("\
-W[no-]traditional Warn about features not present in traditional C\n\
-W[no-]undef Warn if an undefined macro is used by #if\n\
- -W[no-]import Warn about the use of the #import directive\n\
"), stdout);
fputs (_("\
-W[no-]error Treat all warnings as errors\n\
===================================================================
Index: cppfiles.c
--- cppfiles.c 10 Jan 2003 02:21:58 -0000 1.160
+++ cppfiles.c 6 Feb 2003 20:59:55 -0000
@@ -199,14 +199,6 @@ destroy_node (v)
}
}
-/* Mark a file to not be reread (e.g. #import, read failure). */
-void
-_cpp_never_reread (file)
- struct include_file *file;
-{
- file->cmacro = NEVER_REREAD;
-}
-
/* Lookup a filename, which is simplified after making a copy, and
create an entry if none exists. errno is nonzero iff a (reported)
stat() error occurred during simplification. */
@@ -446,14 +438,14 @@ stack_include_file (pfile, inc)
if (read_include_file (pfile, inc))
{
/* If an error occurs, do not try to read this file again. */
- _cpp_never_reread (inc);
+ inc->cmacro = NEVER_REREAD;
return false;
}
/* Mark a regular, zero-length file never-reread. We read it,
NUL-terminate it, and stack it once, so preprocessing a main
file of zero length does not raise an error. */
if (S_ISREG (inc->st.st_mode) && inc->st.st_size == 0)
- _cpp_never_reread (inc);
+ inc->cmacro = NEVER_REREAD;
close (inc->fd);
inc->fd = -1;
}
@@ -824,12 +816,7 @@ _cpp_execute_include (pfile, header, typ
handle_missing_header (pfile, (const char *) header->val.str.text,
header->type == CPP_HEADER_NAME);
else if (inc != NO_INCLUDE_PATH)
- {
- stacked = stack_include_file (pfile, inc);
-
- if (type == IT_IMPORT)
- _cpp_never_reread (inc);
- }
+ stacked = stack_include_file (pfile, inc);
return stacked;
}
===================================================================
Index: cpphash.h
--- cpphash.h 21 Jan 2003 00:12:52 -0000 1.175
+++ cpphash.h 6 Feb 2003 20:59:55 -0000
@@ -151,7 +151,7 @@ struct search_path
};
/* #include types. */
-enum include_type {IT_INCLUDE, IT_INCLUDE_NEXT, IT_IMPORT, IT_CMDLINE};
+enum include_type {IT_INCLUDE, IT_INCLUDE_NEXT, IT_CMDLINE};
union utoken
{
@@ -515,7 +515,6 @@ extern void _cpp_destroy_hashtable PARAM
/* In cppfiles.c */
extern void _cpp_fake_include PARAMS ((cpp_reader *, const char *));
-extern void _cpp_never_reread PARAMS ((struct include_file *));
extern char *_cpp_simplify_pathname PARAMS ((char *));
extern bool _cpp_read_file PARAMS ((cpp_reader *, const char *));
extern bool _cpp_execute_include PARAMS ((cpp_reader *,
===================================================================
Index: cppinit.c
--- cppinit.c 28 Jan 2003 19:29:57 -0000 1.266
+++ cppinit.c 6 Feb 2003 20:59:55 -0000
@@ -519,7 +519,6 @@ cpp_create_reader (lang)
pfile = (cpp_reader *) xcalloc (1, sizeof (cpp_reader));
cpp_set_lang (pfile, lang);
- CPP_OPTION (pfile, warn_import) = 1;
CPP_OPTION (pfile, warn_multichar) = 1;
CPP_OPTION (pfile, discard_comments) = 1;
CPP_OPTION (pfile, discard_comments_in_macro_exp) = 1;
===================================================================
Index: cpplib.c
--- cpplib.c 28 Jan 2003 19:30:00 -0000 1.329
+++ cpplib.c 6 Feb 2003 20:59:56 -0000
@@ -126,7 +126,6 @@ static char ** save_registered_pragmas
PARAMS ((struct pragma_entry *, char **));
static char ** restore_registered_pragmas
PARAMS ((cpp_reader *, struct pragma_entry *, char **));
-static void do_pragma_once PARAMS ((cpp_reader *));
static void do_pragma_poison PARAMS ((cpp_reader *));
static void do_pragma_system_header PARAMS ((cpp_reader *));
static void do_pragma_dependency PARAMS ((cpp_reader *));
@@ -166,7 +165,6 @@ D(pragma, T_PRAGMA, STDC89, IN_I)
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(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, 0) /* 0 SVR4? */
@@ -619,7 +617,7 @@ glue_header_name (pfile)
return header;
}
-/* Returns the header string of #include, #include_next, #import and
+/* Returns the header string of #include, #include_next, and
#pragma dependency. Returns NULL on error. */
static const cpp_token *
parse_include (pfile)
@@ -658,29 +656,13 @@ parse_include (pfile)
return header;
}
-/* Handle #include, #include_next and #import. */
+/* Handle #include and #include_next. */
static void
do_include_common (pfile, type)
cpp_reader *pfile;
enum include_type type;
{
- const cpp_token *header;
-
- /* For #include_next, if this is the primary source file, warn and
- use the normal search logic. */
- if (type == IT_INCLUDE_NEXT && ! pfile->buffer->prev)
- {
- cpp_error (pfile, DL_WARNING, "#include_next in primary source file");
- type = IT_INCLUDE;
- }
- else if (type == IT_IMPORT && CPP_OPTION (pfile, warn_import))
- {
- CPP_OPTION (pfile, warn_import) = 0;
- cpp_error (pfile, DL_WARNING,
- "#import is obsolete, use an #ifndef wrapper in the header file");
- }
-
- header = parse_include (pfile);
+ const cpp_token *header = parse_include (pfile);
if (header)
{
/* Prevent #include recursion. */
@@ -707,17 +689,20 @@ do_include (pfile)
}
static void
-do_import (pfile)
- cpp_reader *pfile;
-{
- do_include_common (pfile, IT_IMPORT);
-}
-
-static void
do_include_next (pfile)
cpp_reader *pfile;
{
- do_include_common (pfile, IT_INCLUDE_NEXT);
+ enum include_type type = IT_INCLUDE_NEXT;
+
+ /* If this is the primary source file, warn and use the normal
+ search logic. */
+ if (! pfile->buffer->prev)
+ {
+ cpp_error (pfile, DL_WARNING, "#include_next in primary source file");
+ type = IT_INCLUDE;
+ }
+
+ do_include_common (pfile, type);
}
/* Subroutine of do_linemarker. Read possible flags after file name.
@@ -1081,9 +1066,6 @@ void
_cpp_init_internal_pragmas (pfile)
cpp_reader *pfile;
{
- /* Pragmas in the global namespace. */
- cpp_register_pragma (pfile, 0, "once", do_pragma_once);
-
/* New GCC-specific pragmas should be put in the GCC namespace. */
cpp_register_pragma (pfile, "GCC", "poison", do_pragma_poison);
cpp_register_pragma (pfile, "GCC", "system_header", do_pragma_system_header);
@@ -1216,22 +1198,6 @@ do_pragma (pfile)
}
pfile->state.prevent_expansion--;
-}
-
-/* Handle #pragma once. */
-static void
-do_pragma_once (pfile)
- cpp_reader *pfile;
-{
- if (CPP_OPTION (pfile, warn_deprecated))
- cpp_error (pfile, DL_WARNING, "#pragma once is obsolete");
-
- if (pfile->buffer->prev == NULL)
- cpp_error (pfile, DL_WARNING, "#pragma once in main file");
- else
- _cpp_never_reread (pfile->buffer->inc);
-
- check_eol (pfile);
}
/* Handle #pragma GCC poison, to poison one or more identifiers so
===================================================================
Index: cpplib.h
--- cpplib.h 28 Jan 2003 19:30:00 -0000 1.242
+++ cpplib.h 6 Feb 2003 20:59:57 -0000
@@ -294,9 +294,6 @@ struct cpp_options
/* Nonzero means warn if there are any trigraphs. */
unsigned char warn_trigraphs;
- /* Nonzero means warn if #import is used. */
- unsigned char warn_import;
-
/* Nonzero means warn about multicharacter charconsts. */
unsigned char warn_multichar;
===================================================================
Index: toplev.c
--- toplev.c 6 Feb 2003 01:47:55 -0000 1.705
+++ toplev.c 6 Feb 2003 20:59:57 -0000
@@ -1291,9 +1291,6 @@ documented_lang_options[] =
{ "-Wno-implicit-int", "" },
{ "-Wimplicit", "" },
{ "-Wno-implicit", "" },
- { "-Wimport",
- N_("Warn about the use of the #import directive") },
- { "-Wno-import", "" },
{ "-Winvalid-pch",
N_("Warn about PCH files that are found but not used") },
{ "-Wlong-long","" },
===================================================================
Index: objc/objc-act.c
--- objc/objc-act.c 31 Jan 2003 14:46:55 -0000 1.164
+++ objc/objc-act.c 6 Feb 2003 21:00:05 -0000
@@ -968,7 +968,7 @@ get_object_reference (protocols)
}
else
{
- error ("undefined type `id', please import <objc/objc.h>");
+ error ("undefined type `id', please include <objc/objc.h>");
return error_mark_node;
}
===================================================================
Index: doc/cpp.texi
--- doc/cpp.texi 26 Jan 2003 20:56:09 -0000 1.53
+++ doc/cpp.texi 6 Feb 2003 21:09:24 -0000
@@ -172,7 +172,6 @@ Implementation Details
Obsolete Features
* Assertions::
-* Obsolete once-only headers::
@end detailmenu
@end menu
@@ -3820,7 +3819,6 @@ In some cases, we plan to remove the fea
@menu
* Assertions::
-* Obsolete once-only headers::
@end menu
@node Assertions
@@ -3907,42 +3905,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
@@ -4025,6 +3987,36 @@ made to correct the behavior, so that th
string constant, but it turned out to be buggy. In 3.1, the bugs have
been fixed. (We are not fixing the bugs in 3.0 because they affect
relatively few people and the fix is quite invasive.)
+
+@item Obsolete once-only headers
+
+@findex #import
+@findex #pragma once
+
+GCC 3.3 and previous supported two special directives to indicate that
+a header file should be read only once. One was a variant of
+@samp{#include} called @samp{#import} which included a file, but only
+once; subsequent uses of @samp{#import} with the same argument would
+not reread the file. This was used primarily in Objective-C@.
+Another was @samp{#pragma once}, which appeared in the file being
+included, and indicated that that file should never be read again. We
+do not know who used this feature.
+
+Neither of these directives were part of the C or C++ standards, and
+therefore they could not be used by portable code in those languages.
+All Objective-C compilers have historically supported @samp{#import};
+that language has never been formally standardized. However, there
+have always been problems with both these directives: header files do
+not necessarily have just one name, and the compiler does not have
+enough information to prove whether or not two names refer to the same
+file. This can cause correct programs that use @samp{#import} or
+@samp{#pragma once} to be rejected for no apparent reason. The
+wrapper @samp{#ifndef} idiom, by contrast, allows the compiler to
+assume that files are distinct when they have different names. If it
+is mistaken, the @samp{#ifndef} will still prevent the code in the
+file from being parsed more than once. The tradeoff is of course that
+the programmer must ensure that guard macros do not clash, but this is
+easy to do.
@end itemize