aboutsummaryrefslogtreecommitdiff
path: root/clang/docs
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-06-14 09:57:21 -0700
committerGitHub <noreply@github.com>2024-06-14 09:57:21 -0700
commit9a92f2f742347d9b31470349f3b777ecab580ac1 (patch)
treefbb7eaa69d6ae094046a5b461e2414051aa9f984 /clang/docs
parentc7b32341e9f885cc7e6ba4b2ff017f748a6f76ee (diff)
downloadllvm-9a92f2f742347d9b31470349f3b777ecab580ac1.zip
llvm-9a92f2f742347d9b31470349f3b777ecab580ac1.tar.gz
llvm-9a92f2f742347d9b31470349f3b777ecab580ac1.tar.bz2
Make diagnostic pragma override -Werror=foo and DefaultError warnings
In GCC, `#pragma GCC diagnostic warning "-Wfoo"` overrides command-line `-Werror=foo` and errors that can become warnings (pedwarn with -pedantic-errors and permerror). ``` #pragma GCC diagnostic warning "-Wnarrowing" int x = {4.2}; #pragma GCC diagnostic warning "-Wundef" #if FOO #endif // gcc -c -Werror=undef -Werror=narrowing => two warnings ``` These diagnostics are similar to our Warning/ExtWarn/Extension diagnostics with DefaultError. This patch ports the behavior to Clang. Fix #93474 Pull Request: https://github.com/llvm/llvm-project/pull/93647
Diffstat (limited to 'clang/docs')
-rw-r--r--clang/docs/ReleaseNotes.rst3
-rw-r--r--clang/docs/UsersManual.rst11
2 files changed, 13 insertions, 1 deletions
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bae9f5e..36efeb8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -351,6 +351,9 @@ Non-comprehensive list of changes in this release
- Added ``__is_bitwise_cloneable`` which is used to check whether a type
can be safely copied by memcpy/memmove.
+- ``#pragma GCC diagnostic warning "-Wfoo"`` can now downgrade ``-Werror=foo``
+ errors and certain default-to-error ``-W`` diagnostics to warnings.
+
New Compiler Flags
------------------
- ``-fsanitize=implicit-bitfield-conversion`` checks implicit truncation and
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 15bf5e3..8e01ea1 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1138,7 +1138,7 @@ and ``#pragma clang diagnostic`` are synonyms for Clang. GCC will ignore
The pragma may control any warning that can be used from the command
line. Warnings may be set to ignored, warning, error, or fatal. The
-following example code will tell Clang or GCC to ignore the -Wall
+following example code will tell Clang or GCC to ignore the ``-Wall``
warnings:
.. code-block:: c
@@ -1186,6 +1186,15 @@ severity levels. They can be used to change severity of a particular diagnostic
for a region of source file. A notable difference from GCC is that diagnostic
not enabled via command line arguments can't be enabled this way yet.
+Some diagnostics associated with a ``-W`` flag have the error severity by
+default. They can be ignored or downgraded to warnings:
+
+.. code-block:: cpp
+
+ // C only
+ #pragma GCC diagnostic warning "-Wimplicit-function-declaration"
+ int main(void) { puts(""); }
+
In addition to controlling warnings and errors generated by the compiler, it is
possible to generate custom warning and error messages through the following
pragmas: