[clang] [Clang] [NFC] Introduce helpers for defining compatibilty warnings (PR #132129)

via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 20 09:40:55 PDT 2025


================
@@ -155,6 +155,38 @@ class DefaultWarnNoWerror {
 }
 class DefaultRemark { Severity DefaultSeverity = SEV_Remark; }
 
+// C++ compatibility warnings.
+multiclass CXXCompat<
+    string message,
+    int std_ver,
+    bit ext_warn = true,
+    string std_ver_override = ""#std_ver> {
+    // 'X is a C++YZ extension'.
+    def compat_pre_cxx#std_ver#_#NAME :
+        Diagnostic<!strconcat(message, " a C++", std_ver_override,  " extension"),
+                   CLASS_EXTENSION,
+                   !if(ext_warn, SEV_Warning, SEV_Ignored)>,
+        InGroup<!cast<DiagGroup>("CXX"#std_ver)>;
+
+    // 'X is incompatible with C++98' (if std_ver == 11).
+    // 'X is incompatible with C++ standards before C++YZ' (otherwise).
+    def compat_cxx#std_ver#_#NAME :
+        Warning<!if(!eq(std_ver, 11),
+                    !strconcat(message, " incompatible with C++98"),
+                    !strconcat(message, " incompatible with C++ standards before C++", std_ver_override))>,
+        InGroup<!cast<DiagGroup>(!if(!eq(std_ver, 11),
+                                     "CXX98Compat",
+                                     "CXXPre"#std_ver#"Compat"))>,
+        DefaultIgnore;
+}
+
+multiclass CXX11Compat<string message, bit ext_warn = true> : CXXCompat<message, 11, ext_warn>;
----------------
Sirraide wrote:

> The reason it's beneficial is because it helps the reader understand "this code is an extension" vs "this code is standard functionality". We could also accomplish that with the helper function call rather than the diagnostic name itself, though.

Yeah, I feel like in the case of compatibility warnings it kind of goes without saying that it’s an extension, but yeah, a helper function would definitely help with that.

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


More information about the cfe-commits mailing list