[clang] [Clang][Diagnostics] Update select uses in DiagnosticXKinds.td to use enum_select (PR #130868)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 13 11:24:28 PDT 2025
================
@@ -131,17 +131,21 @@ def note_constexpr_past_end : Note<
"dereferenced pointer past the end of %select{|subobject of }0"
"%select{temporary|%2}1 is not a constant expression">;
def note_constexpr_past_end_subobject : Note<
- "cannot %select{access base class of|access derived class of|access field of|"
- "access array element of|ERROR|"
- "access real component of|access imaginary component of}0 "
- "pointer past the end of object">;
+ "cannot %enum_select<AccessType>{"
+ "%BaseClassAccess{access base class of}|%DerivedClassAccess{access derived class of}|"
+ "%FieldAccess{access field of}|%ArrayElementAccess{access array element of}|"
+ "%ErrorAccess{ERROR}|"
+ "%RealComponentAccess{access real component of}|%ImaginaryComponentAccess{access imaginary component of}"
+ "}0 pointer past the end of object">;
def note_non_null_attribute_failed : Note<
"null passed to a callee that requires a non-null argument">;
def note_constexpr_null_subobject : Note<
- "cannot %select{access base class of|access derived class of|access field of|"
- "access array element of|perform pointer arithmetic on|"
- "access real component of|"
- "access imaginary component of}0 null pointer">;
+ "cannot %enum_select<NullSubobjectAccess>{"
----------------
Sirraide wrote:
> The re-use of the same text like that is interesting.... I'd not thought of doing something like that (without the curleys), but I'm a touch afraid it harms readability of the diagnostic.
I mean, I personally wouldn’t consider
```
cannot %enum_select<NullSubobjectAccess>{
"%BaseClassAccess{access base class of}|%DerivedClassAccess{access derived class of}|"
"%FieldAccess{access field of}|%ArrayElementAccess{access array element of}|"
"%PointerArithmetic{perform pointer arithmetic on}|"
"%RealComponentAccess{access real component of}|%ImaginaryComponentAccess{access imaginary component of}"
"}0 null pointer
```
to be more readable than
```
cannot %enum_select<NullSubobjectAccess>0 null pointer
```
I’d imagine that in cases where we’d want to reuse the enumeration, it wouldn’t be too uncommon to also want to reuse the text, but I haven’t checked. This was just an idea I had earlier while looking at this pr because here we *do* have some diagnostics that more or less just share the same text.
https://github.com/llvm/llvm-project/pull/130868
More information about the cfe-commits
mailing list