================
@@ -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}}
----------------
AaronBallman wrote:

Do we want to allow `-Wno-error=foo` to work for diagnostics which are 
explicitly an error in the attribute? We don't let users do things like that 
for other errors and that suggests that `"error"` in `disable_if` is actually 
"warning that defaults to an error" rather than an error.

https://github.com/llvm/llvm-project/pull/70976
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to