diff options
author | Lewis Hyatt <lhyatt@gmail.com> | 2022-07-12 09:47:47 -0400 |
---|---|---|
committer | Lewis Hyatt <lhyatt@gmail.com> | 2022-07-31 07:48:47 -0400 |
commit | b04c399e258e686dddad879bf7e27d9e28fd6fde (patch) | |
tree | 3622374d5d78bfc193a2a43e8da5304ec168143d /gcc/cp/parser.cc | |
parent | 351e3cad2c5d4dfe43d68ba333bde1d70fa0b807 (diff) | |
download | gcc-b04c399e258e686dddad879bf7e27d9e28fd6fde.zip gcc-b04c399e258e686dddad879bf7e27d9e28fd6fde.tar.gz gcc-b04c399e258e686dddad879bf7e27d9e28fd6fde.tar.bz2 |
c++: Fix location for -Wunused-macros [PR66290]
In C++, since all tokens are lexed from libcpp up front, diagnostics generated
by libcpp after lexing has completed do not get a valid location from libcpp
(rather, libcpp thinks they all pertain to the end of the file.) This has long
been addressed using the global variable "done_lexing", which the C++ frontend
sets at the appropriate time; when done_lexing is true, then c_cpp_diagnostic(),
which outputs libcpp's diagnostics, uses input_location instead of the wrong
libcpp location. The C++ frontend arranges that input_location will point to the
token it is currently processing, so this generally works fine. However, there
is one exception currently, which is -Wunused-macros. This gets generated at the
end of processing in cpp_finish (), since we need to wait until then to
determine whether a macro was eventually used or not. But the locations it
passes to c_cpp_diagnostic () were remembered from the original lexing and hence
they should not be overridden with input_location, which is now the one
incorrectly pointing to the end of the file.
Fixed by setting done_lexing=false again just prior to calling cpp_finish (). I
also renamed the variable from done_lexing to "override_libcpp_locations", since
it's now not strictly about lexing anymore.
There is no new testcase with this patch, since we already had an xfailed
testcase which is now fixed.
gcc/c-family/ChangeLog:
PR c++/66290
* c-common.h: Rename global done_lexing to
override_libcpp_locations.
* c-common.cc (c_cpp_diagnostic): Likewise.
* c-opts.cc (c_common_finish): Set override_libcpp_locations
(formerly done_lexing) immediately prior to calling cpp_finish ().
gcc/cp/ChangeLog:
PR c++/66290
* parser.cc (cp_lexer_new_main): Rename global done_lexing to
override_libcpp_locations.
gcc/testsuite/ChangeLog:
PR c++/66290
* c-c++-common/pragma-diag-15.c: Remove xfail for C++.
Diffstat (limited to 'gcc/cp/parser.cc')
-rw-r--r-- | gcc/cp/parser.cc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 826595a..33926d2 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -755,7 +755,7 @@ cp_lexer_new_main (void) /* Subsequent preprocessor diagnostics should use compiler diagnostic functions to get the compiler source location. */ - done_lexing = true; + override_libcpp_locations = true; maybe_check_all_macros (parse_in); |