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

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 20 07:26:56 PDT 2025


erichkeane wrote:

> LGTM but please wait for some additional opinions from other reviewers before landing.

I don't actually spend much time writing compatibility warnings, but think this is an improvement.  

As a followup perhaps, I would LOVE it if we could modify the DiagnosticsEmitter to make the calls here be `CompatDiag(SrcLoc, DiagBASE)`.

WHERE: 
1- It determines the C++ standard version itself, so it checks LangOpts so we don't have to actually tell it what standards verseion.

2- Where the unsigned it takes is actually an index/etc into a decoder.  The decoder is just a function that gets generated, so perhaps something like:

```
int Sema::CompatDiag(SourceLocation Loc, unsigned DiagBase) {
  unsigned DiagId = DecodeCompatDiag(getLangOpts(), DiagBase);
  return Diag(Loc, DiagId);
}
// the below is generated:
unsigned DecodeCompatDiag(LangOpts &LO, unsigned DiagBase) {
  switch(DiagBase) {
       case diag_compat::compat_cxx20_foo:
           return LO.CPlusPlus20 ? diag::compat_cxx20_foo : diag::compat_pre_cxx20_foo;
       ...
  }
}
```

BUT As I said, what we have in this patch is at least an improvement, and is perhaps OK because of that.

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


More information about the cfe-commits mailing list