rsmith added a comment.

C++20 designated initializers don't permit mixing designated fields with 
non-designated ones, so some of the examples here are invalid. However, I think 
we should be looking for an attribute design that works well in both C and C++, 
and with the various Clang extensions that permit the full generality of C 
designated initializers in other language modes. I also think this patch is 
combining multiple features that would be useful to expose separately. To that 
end, I think something like this might make sense:

- An attribute that can be applied to either a field or to a struct that 
requires a designator to be used on any initializer for that field (and for a 
struct, is equivalent to specifying the attribute on all fields)
- An attribute that can be applied to either a field or to a struct that 
requires an explicit initializer to be used for that field, for both aggregate 
initialization and constructor mem-initializer lists (and for a struct, is 
equivalent to specifying the attribute on all fields with no default member 
initializers)

Maybe `requires_designator` and `requires_init` or similar?

And I think these attributes should be made available in both C++11 attribute 
syntax and GNU attribute syntax. Inventing a C++-only extension to improve 
support for designated initializers doesn't seem like the right choice to me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64380/new/

https://reviews.llvm.org/D64380



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to