[llvm] [Support] Add automatic index assignment in formatv (PR #107459)

River Riddle via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 11 15:33:09 PDT 2024


================
@@ -167,16 +167,19 @@ template <typename Tuple> class formatv_object : public formatv_object_base {
 // Formats textual output.  `Fmt` is a string consisting of one or more
 // replacement sequences with the following grammar:
 //
-// rep_field ::= "{" index ["," layout] [":" format] "}"
+// rep_field ::= "{" [index] ["," layout] [":" format] "}"
 // index     ::= <non-negative integer>
 // layout    ::= [[[char]loc]width]
 // format    ::= <any string not containing "{" or "}">
 // char      ::= <any character except "{" or "}">
 // loc       ::= "-" | "=" | "+"
 // width     ::= <positive integer>
 //
-// index   - A non-negative integer specifying the index of the item in the
-//           parameter pack to print.  Any other value is invalid.
+// index   - An optional non-negative integer specifying the index of the item
+//           in the parameter pack to print. Any other value is invalid. If its
+//           not specified, it will be automatically assigned a value based on
+//           the order of rep_field seen in the format string. Note that mixing
+//           automatic and explicit index in the same call is undefined.
----------------
River707 wrote:

When I originally read this I was going to ask if this could be an error, but saw you already added an error for this. Can the language here be changed to be stronger? `undefined` leads me to believe you can do it, but seems like this should be explicitly noted as disallowed (describing directly that this is an error).

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


More information about the llvm-commits mailing list