[clang] [clang-tools-extra] [clang] Extend diagnose_if to accept more detailed warning information (PR #70976)

Nikolas Klauser via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 9 02:35:45 PST 2023


================
@@ -171,13 +172,61 @@ class DiagnosticMapping {
 class DiagnosticIDs : public RefCountedBase<DiagnosticIDs> {
 public:
   /// The level of the diagnostic, after it has been through mapping.
-  enum Level {
+  enum Level : uint8_t {
     Ignored, Note, Remark, Warning, Error, Fatal
   };
 
+  // Diagnostic classes.
+  enum Class {
+    CLASS_NOTE       = 0x01,
+    CLASS_REMARK     = 0x02,
+    CLASS_WARNING    = 0x03,
+    CLASS_EXTENSION  = 0x04,
+    CLASS_ERROR      = 0x05
+  };
+
+  struct CustomDiagDesc {
+    diag::Severity DefaultSeverity : 3 = diag::Severity::Warning;
+    unsigned Class : 3 = CLASS_WARNING;
+    unsigned ShowInSystemHeader : 1 = false;
+    unsigned ShowInSystemMacro : 1 = false;
+    unsigned HasGroup : 1 = false;
+    diag::Group Group = {};
+    std::string Description;
+
+    friend bool operator==(const CustomDiagDesc &lhs, const CustomDiagDesc &rhs) {
+      return lhs.DefaultSeverity == rhs.DefaultSeverity &&
+              lhs.Class == rhs.Class &&
+              lhs.ShowInSystemHeader == rhs.ShowInSystemHeader &&
+              lhs.ShowInSystemMacro == rhs.ShowInSystemMacro &&
+              lhs.HasGroup == rhs.HasGroup &&
+              (!lhs.HasGroup || lhs.Group == rhs.Group) &&
----------------
philnik777 wrote:

I guess you're right. I've added a constructor to make sure it's actually an invariant. The `std::tie` didn't quite work, since it's binding to temporaries of the bitfields. I've made a value-tuple instead and that simplifies the code a lot. Thanks!

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


More information about the cfe-commits mailing list