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:
Ken Matsui
2024-03-01 22:10:55 -08:00
parent 41179a3276
commit 821d56100e
7 changed files with 30 additions and 4 deletions

View 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