From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 66828396D831; Mon, 11 Jul 2022 21:53:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 66828396D831 From: "lhyatt at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/66290] wrong location for -Wunused-macros Date: Mon, 11 Jul 2022 21:53:48 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 7.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: lhyatt at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Jul 2022 21:53:48 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D66290 Lewis Hyatt changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |lhyatt at gcc dot gnu.org --- Comment #3 from Lewis Hyatt --- (https://gcc.gnu.org/pipermail/gcc-patches/2022-July/598188.html) This testcase, hopefully soon to be committed as c-c++-common/pragma-diag-1= 5.c: ------- /* { dg-do compile } */ /* { dg-additional-options "-Wunused-macros" } */ #define X /* { dg-warning "-:-Wunused-macros" {} { xfail c++ } } */ #pragma GCC diagnostic ignored "-Wunused-macros" ------- fails for C++, I believe it's the same thing pointed out in this PR. The re= ason is because of this in c_cpp_diagnostic() in c-common.cc: ------- if (done_lexing) richloc->set_range (0, input_location, SHOW_RANGE_WITH_CARET); ------- This warning is issued at the end of compilation, when done_lexing is true. However, input_location is not the right thing to use here, the location provided was remembered from the time the macro was lexed, and that's the o= ne that needs to be used. The way it is now, input_location is at the end of t= he file, and so the macro is deemed to have been defined after the #pragma. I think this done_lexing concept was added to solve PR17964 many years ago. Does anyone know if it's still needed, are there still cases where libcpp c= an generate a diagnostic while C++ is parsing the already-lexed tokens? I have checked anyway, that the particular testcase on PR17964 passes if done_lexi= ng is kept always false. I am trying the full testsuite now as well. If it can= 't be removed, then I think we need some way to tell c_cpp_diagnostic not to override a location for instances like this. Or paradoxically, we could set done_lexing=3Dfalse in c_common_finish(), which would fix it as well. It fi= xes both my testcase, and the one in this original PR. Could be a reasonable fi= x, perhaps combined with renaming done_lexing to something more like override_libcpp_locations, but would be nice if it could just be removed as well. I can look into that but perhaps Joseph knows the details here alread= y? diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index b9f01a65ed7..25a3c50de8e 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -1283,6 +1283,7 @@ c_common_finish (void) /* For performance, avoid tearing down cpplib's internal structures with cpp_destroy (). */ + done_lexing =3D false; cpp_finish (parse_in, deps_stream); if (deps_stream && deps_stream !=3D out_stream && deps_stream !=3D stdou= t=