[clang] Add 'enum_select' diagnostic selection to clang. (PR #122505)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 14 11:40:17 PST 2025


================
@@ -0,0 +1,16 @@
+// RUN: clang-tblgen --gen-clang-diags-enums -I%S %s 2>&1 | FileCheck %s
+include "DiagnosticBase.inc"
+
+def DupeNames1 : Error<"%enum_select<DupeName>{}0">;
+def DupeNames2 : Error<"%enum_select<DupeName>{}0">;
+// CHECK: error: Duplicate enumeration name 'DupeName'
+// CHECK-NEXT: def DupeNames2
+// CHECK: note: Previous diagnostic is here
+// CHECK-NEXT: def DupeNames1
+
+def DupeValue : Error<"%enum_select<DupeValue>{%Name{V1}|%Name{V2}}0">;
+// CHECK: error: Duplicate enumerator name 'Name'
+
+def EnumValNotExpected : Error<"%enum_select{V1|%Val2{V2}}0">;
----------------
erichkeane wrote:

I thought about that.  We end up not diagnosing a lot of this sort of thing, so I didn't know how much value there was to it, particularly when continuing to build will cause the error later when the enum fails to parse/compile.  If we have a good function to test for it, I could potentially error on a non-identifier character?

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


More information about the cfe-commits mailing list