mirror of
https://gcc.gnu.org/git/gcc.git
synced 2026-02-21 19:35:28 -05:00
gcc, libcpp: Add warning switch for "#pragma once in main file" [PR89808]
This patch adds a warning switch for "#pragma once in main file". The warning option name is Wpragma-once-outside-header, which is the same as Clang provides. PR preprocessor/89808 gcc/c-family/ChangeLog: * c.opt (Wpragma_once_outside_header): Define new option. * c.opt.urls: Regenerate. gcc/ChangeLog: * doc/invoke.texi (Warning Options): Document -Wno-pragma-once-outside-header. libcpp/ChangeLog: * include/cpplib.h (cpp_warning_reason): Define CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER. * directives.cc (do_pragma_once): Use CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER. gcc/testsuite/ChangeLog: * g++.dg/warn/Wno-pragma-once-outside-header.C: New test. * g++.dg/warn/Wpragma-once-outside-header.C: New test. Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org> Reviewed-by: Marek Polacek <polacek@redhat.com>
This commit is contained in:
@@ -1214,6 +1214,10 @@ Wpragmas
|
||||
C ObjC C++ ObjC++ Var(warn_pragmas) Init(1) Warning
|
||||
Warn about misuses of pragmas.
|
||||
|
||||
Wpragma-once-outside-header
|
||||
C ObjC C++ ObjC++ Var(warn_pragma_once_outside_header) CppReason(CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER) Init(1) Warning
|
||||
Warn about #pragma once outside of a header.
|
||||
|
||||
Wprio-ctor-dtor
|
||||
C ObjC C++ ObjC++ Var(warn_prio_ctor_dtor) Init(1) Warning
|
||||
Warn if constructor or destructors with priorities from 0 to 100 are used.
|
||||
|
||||
@@ -684,6 +684,9 @@ UrlSuffix(gcc/Warning-Options.html#index-Wno-pointer-to-int-cast)
|
||||
Wpragmas
|
||||
UrlSuffix(gcc/Warning-Options.html#index-Wno-pragmas)
|
||||
|
||||
Wpragma-once-outside-header
|
||||
UrlSuffix(gcc/Warning-Options.html#index-Wno-pragma-once-outside-header)
|
||||
|
||||
Wprio-ctor-dtor
|
||||
UrlSuffix(gcc/Warning-Options.html#index-Wno-prio-ctor-dtor)
|
||||
|
||||
|
||||
@@ -395,8 +395,8 @@ Objective-C and Objective-C++ Dialects}.
|
||||
-Wpacked -Wno-packed-bitfield-compat -Wpacked-not-aligned -Wpadded
|
||||
-Wparentheses -Wno-pedantic-ms-format
|
||||
-Wpointer-arith -Wno-pointer-compare -Wno-pointer-to-int-cast
|
||||
-Wno-pragmas -Wno-prio-ctor-dtor -Wredundant-decls
|
||||
-Wrestrict -Wno-return-local-addr -Wreturn-type
|
||||
-Wno-pragmas -Wno-pragma-once-outside-header -Wno-prio-ctor-dtor
|
||||
-Wredundant-decls -Wrestrict -Wno-return-local-addr -Wreturn-type
|
||||
-Wno-scalar-storage-order -Wsequence-point
|
||||
-Wshadow -Wshadow=global -Wshadow=local -Wshadow=compatible-local
|
||||
-Wno-shadow-ivar
|
||||
@@ -8147,6 +8147,12 @@ Do not warn about misuses of pragmas, such as incorrect parameters,
|
||||
invalid syntax, or conflicts between pragmas. See also
|
||||
@option{-Wunknown-pragmas}.
|
||||
|
||||
@opindex Wno-pragma-once-outside-header
|
||||
@opindex Wpragma-once-outside-header
|
||||
@item -Wno-pragma-once-outside-header
|
||||
Do not warn when @code{#pragma once} is used in a file that is not a header
|
||||
file, such as a main file.
|
||||
|
||||
@opindex Wno-prio-ctor-dtor
|
||||
@opindex Wprio-ctor-dtor
|
||||
@item -Wno-prio-ctor-dtor
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// { dg-do assemble }
|
||||
// { dg-options "-Wno-pragma-once-outside-header" }
|
||||
|
||||
#pragma once
|
||||
int main() {}
|
||||
6
gcc/testsuite/g++.dg/warn/Wpragma-once-outside-header.C
Normal file
6
gcc/testsuite/g++.dg/warn/Wpragma-once-outside-header.C
Normal file
@@ -0,0 +1,6 @@
|
||||
// { dg-do assemble }
|
||||
// { dg-options "-Werror=pragma-once-outside-header" }
|
||||
// { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 }
|
||||
|
||||
#pragma once // { dg-error "'#pragma once' in main file" }
|
||||
int main() {}
|
||||
@@ -2074,7 +2074,8 @@ static void
|
||||
do_pragma_once (cpp_reader *pfile)
|
||||
{
|
||||
if (_cpp_in_main_source_file (pfile))
|
||||
cpp_error (pfile, CPP_DL_WARNING, "#pragma once in main file");
|
||||
cpp_warning (pfile, CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER,
|
||||
"%<#pragma once%> in main file");
|
||||
|
||||
check_eol (pfile, false);
|
||||
_cpp_mark_file_once_only (pfile, pfile->buffer->file);
|
||||
|
||||
@@ -714,7 +714,8 @@ enum cpp_warning_reason {
|
||||
CPP_W_BIDIRECTIONAL,
|
||||
CPP_W_INVALID_UTF8,
|
||||
CPP_W_UNICODE,
|
||||
CPP_W_HEADER_GUARD
|
||||
CPP_W_HEADER_GUARD,
|
||||
CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER
|
||||
};
|
||||
|
||||
/* Callback for header lookup for HEADER, which is the name of a
|
||||
|
||||
Reference in New Issue
Block a user