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

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 28 13:37:02 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) &&
+              lhs.Description == rhs.Description;
+    }
+
+    friend bool operator<(const CustomDiagDesc& lhs, const CustomDiagDesc& rhs) {
+      if (lhs.DefaultSeverity != rhs.DefaultSeverity)
----------------
erichkeane wrote:

Can you implement this with the 'std::tie' trick here?  As far as I can tell, thats what you're doing here.

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


More information about the cfe-commits mailing list