[clang] [Clang] [NFC] Introduce a helper for emitting compatibility diagnostics (PR #132348)

via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 21 07:02:46 PDT 2025


================
@@ -769,6 +770,51 @@ StringRef DiagnosticIDs::getNearestOption(diag::Flavor Flavor,
   return Best;
 }
 
+unsigned DiagnosticIDs::getCompatDiagId(const LangOptions &LangOpts,
+                                        unsigned CompatDiagId) {
+  struct CompatDiag {
+    unsigned StdVer;
+    unsigned DiagId;
+    unsigned PreDiagId;
+  };
+
+  // We encode the standard version such that C++98 < C++11 < C++14 etc. The
+  // actual numbers don't really matter for this, but the definitions of the
+  // compat diags in the Tablegen file use the standard version number (i.e.
+  // 98, 11, 14, etc.), so we base the encoding here on that.
+#define DIAG_COMPAT_IDS_BEGIN()
+#define DIAG_COMPAT_IDS_END()
+#define DIAG_COMPAT_ID(Value, Name, Std, Diag, DiagPre)                        \
+  {Std == 98 ? 1998 : 2000 + Std, diag::Diag, diag::DiagPre},
----------------
Sirraide wrote:

> Can we just expand this whole thing to work for C as well?

Yes, the plan is to expand this so it can also be used for C compatibility warnings; I’m not 100% sure how that is going to work just yet though.

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


More information about the cfe-commits mailing list