[clang] [clang][driver] Improve warning message for complex range overrides and GCC incompatibility (PR #149028)

Shunsuke Watanabe via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 16 00:13:50 PDT 2025


s-watanabe314 wrote:

This patch is a draft. I created it because I thought it would be easier to discuss the behavior of overriding and GCC incompatibility warnings related to complex range with concrete examples of implementation and tests. In this implementation example, each warning will behave as follows:

1. Override Warning:
    When a complex range override occurs, display the option that triggered it and the complex range value implied by that option.
    Example:
    ```
    $ clang foo.cpp -fcx-fortran-rules -fcx-limited-range -Wno-gcc-compat
    clang: warning: '-fcx-limited-range' sets complex range to "basic" overriding the setting of "improved" that was implied by '-fcx-fortran-rules' [-Woverriding-complex-range]
    ```
1. GCC Incompatibility Warning:
    When the override behavior is incompatible with GCC, warn about it and show how to resolve it.
    Example:
    ```
    $ clang foo.cpp -fcx-fortran-rules -fcx-limited-range -Wno-overriding-complex-range
    clang: warning: complex number caluculation is incompatible with GCC; specify '-fcx-fortran-rules' after '-fcx-limited-range' for compatibility [-Wgcc-compat]
    ````
1. Combined Warning:
    If both override and incompatibility warnings are needed simultaneously, combine the warning messages into one. This combined warning is output when both `-Woverriding-complex-range` and `-Wgcc-compat` are enabled. If the user specifies `-Wno-overriding-complex-range` or `-Wno-gcc-compat`, the warning message from 1 or 2 is selectively output.
    Example:
    ```
    $ clang foo.cpp -fcx-fortran-rules -fcx-limited-range                              
    clang: warning: '-fcx-limited-range' sets complex range to "basic" overriding the setting of "improved" that was implied by '-fcx-fortran-rules' and this is incompatible with GCC; specify '-fcx-fortran-rules' after '-fcx-limited-range' for compatibility [-Wgcc-compat]
    ```
The test `range-warning.c` only covers some cases so far, but I plan to create comprehensive tests when I submit a formal pull request. If this behavior and implementation look good, I will create a formal pull request including all the tests.

https://github.com/llvm/llvm-project/pull/149028


More information about the cfe-commits mailing list