================
@@ -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}}
+}
----------------
AaronBallman wrote:
Additional test coverage I'd like to see:
`diagnose_if(true, "oh no", "warning", "all")` -- Ensure `-Wall` enables the
warning and `-Wno-all` disables it
`diagnose_if(true, "oh no", "warning", "pedantic")` -- Ensure `-Wpedantic`
enables the warning, `-Wno-pedantic` disables it, and `-pedantic` does not turn
it on (do we agree that `-Wpedantic` and `-pedantic` are different?).
`diagnose_if(true, "oh no", "warning", "format-nonliteral")` -- Ensure that
`-Wformat` enables the warning and that `-Wno-format-nonliteral` and
`-Wno-format` both disable the warning.
(And maybe coverage for pragma variants of the above cases?)
https://github.com/llvm/llvm-project/pull/70976
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits