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

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 20 05:26:15 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>;
----------------
AaronBallman wrote:

It would help to have leading comments that say:
```
// Generates compat_cxx11_<diag_name> and compat_pre_cxx11_<diag_name> diagnostic IDs.
```
so it's more clear what the name of the diagnostic will be.

Note, we usually have a convention that extension warnings are prefixed with `ext`, warnings are prefixed with `warn`; should we retain that convention?

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


More information about the cfe-commits mailing list