[clang] [clang-tools-extra] [clang] Extend diagnose_if to accept more detailed warning information (PR #70976)
Nikolas Klauser via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 14 04:01:27 PDT 2024
================
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 %s -verify -fno-builtin -Werror=comment -Wno-error=abi -Wfatal-errors=assume -Wno-fatal-errors=assume
+
+#define diagnose_if(...) __attribute__((diagnose_if(__VA_ARGS__)))
+
+template <bool b>
+void diagnose_if_wcomma() diagnose_if(b, "oh no", "warning", "comma") {}
+
+template <bool b>
+void diagnose_if_wcomment() diagnose_if(b, "oh no", "warning", "comment") {}
+
+void bougus_warning() diagnose_if(true, "oh no", "warning", "bougus warning") {} // expected-error {{unknown warning group}}
+
+void show_in_system_header() diagnose_if(true, "oh no", "warning", "assume", "Banane") {} // expected-error {{'diagnose_if' attribute takes no more than 4 arguments}}
+
+
+void diagnose_if_wabi_default_error() diagnose_if(true, "ABI stuff", "error", "abi") {}
+void diagnose_assume() diagnose_if(true, "Assume diagnostic", "warning", "assume") {}
+
+void call() {
+ diagnose_if_wcomma<true>(); // expected-warning {{oh no}}
+ diagnose_if_wcomma<false>();
+ diagnose_if_wcomment<true>(); // expected-error {{oh no}}
+ diagnose_if_wcomment<false>();
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wcomma"
+ diagnose_if_wcomma<true>();
+ diagnose_if_wcomment<true>(); // expected-error {{oh no}}
+#pragma clang diagnostic pop
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wcomment"
+ diagnose_if_wcomma<true>(); // expected-warning {{oh no}}
+ diagnose_if_wcomment<true>();
+#pragma clang diagnostic pop
+
+ diagnose_if_wcomma<true>(); // expected-warning {{oh no}}
+ diagnose_if_wcomment<true>(); // expected-error {{oh no}}
+
+ diagnose_if_wabi_default_error(); // expected-warning {{ABI stuff}}
+ diagnose_assume(); // expected-error {{Assume diagnostic}}
+
+ // Make sure that the -Wassume diagnostic isn't fatal
+ diagnose_if_wabi_default_error(); // expected-warning {{ABI stuff}}
+}
----------------
philnik777 wrote:
I don't think `-Wpedantic` and `-pedantic` should be in any way different. It also feels very weird to say that we enable a `diagnose_if` that's in `-Wpedantic` only if we're passing `-Wpedantic`, but not if we're passing `-pedantic`, since `-pedantic` is just enabling all the warnings is `-Wpedantic` AFAICT. Because of https://godbolt.org/z/sK11rjxsa it's also kinda hard to add a test right now, since we don't have default ignore as an option currently.
https://github.com/llvm/llvm-project/pull/70976
More information about the cfe-commits
mailing list