https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118838

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Lewis Hyatt <lhy...@gcc.gnu.org>:

https://gcc.gnu.org/g:78673484b4055b93207eee0efd60a434b0bf96ab

commit r16-179-g78673484b4055b93207eee0efd60a434b0bf96ab
Author: Lewis Hyatt <lhy...@gmail.com>
Date:   Tue Feb 11 13:45:41 2025 -0500

    c-family: Improve location for -Wunknown-pragmas in a _Pragma [PR118838]

    The warning for -Wunknown-pragmas is issued at the location provided by
    libcpp to the def_pragma() callback. This location is
    cpp_reader::directive_line, which is a location for the start of the line
    only; it is also not a valid location in case the unknown pragma was lexed
    from a _Pragma string. These factors make it impossible to suppress
    -Wunknown-pragmas via _Pragma("GCC diagnostic...") directives on the same
    source line, as in the PR and the test case. Address that by issuing the
    warning at a better location returned by cpp_get_diagnostic_override_loc().
    libcpp already maintains this location to handle _Pragma-related
diagnostics
    internally; it was needed also to make a publicly accessible version of it.

    gcc/c-family/ChangeLog:

            PR c/118838
            * c-lex.cc (cb_def_pragma): Call cpp_get_diagnostic_override_loc()
            to get a valid location at which to issue -Wunknown-pragmas, in
case
            it was triggered from a _Pragma.

    libcpp/ChangeLog:

            PR c/118838
            * errors.cc (cpp_get_diagnostic_override_loc): New function.
            * include/cpplib.h (cpp_get_diagnostic_override_loc): Declare.

    gcc/testsuite/ChangeLog:

            PR c/118838
            * c-c++-common/cpp/pragma-diagnostic-loc-2.c: New test.
            * g++.dg/gomp/macro-4.C: Adjust expected output.
            * gcc.dg/gomp/macro-4.c: Likewise.
            * gcc.dg/cpp/Wunknown-pragmas-1.c: Likewise.
  • [Bug c/118838] _Pragma diagnost... cvs-commit at gcc dot gnu.org via Gcc-bugs

Reply via email to