From d8517c959bbc3315fa17e33d95fba1cc77a010a8 Mon Sep 17 00:00:00 2001
From: Arthur Sonzogni <arthursonzogni@chromium.org>
Date: Fri, 3 Mar 2023 09:41:45 +0000
Subject: [PATCH] C++ styleguide: allow designated initializer.

They are allowed by the Google style guide, and used in Chrome.
https://groups.google.com/a/chromium.org/g/cxx/c/YTuYWSNOpS8/m/eyMr3XxrAgAJ

Nevertheless, it is a bit ambiguous, because of the chromium coding
style. Indeed, some developers interpret the sentence "C++20: Not yet
supported in Chromium" as an ban of the feature.

This patch make it explicit the Chromium coding style do not contradict
the Google coding style here.

Bug: None
Change-Id: I8571c9d74e1e22525574c9609c6d07d022c3592e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4301374
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1112689}
---
 styleguide/c++/c++-features.md | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/styleguide/c++/c++-features.md b/styleguide/c++/c++-features.md
index 312f968aced3e..299061566db15 100644
--- a/styleguide/c++/c++-features.md
+++ b/styleguide/c++/c++-features.md
@@ -32,7 +32,8 @@ The current status of existing standards and Abseil features is:
 *   **C++14:** _Default allowed_
 *   **C++17:** Initially supported December 23, 2021; see allowed/banned/TBD
     features below
-*   **C++20:** _Not yet supported in Chromium_
+*   **C++20:** _Not yet supported in Chromium_, with the exception of
+    [designated initializers](https://google.github.io/styleguide/cppguide.html#Designated_initializers)
 *   **C++23:** _Not yet standardized_
 *   **Abseil:** _Default allowed; see banned/TBD features below_
       * absl::AnyInvocable: Initially supported June 20, 2022
@@ -1506,6 +1507,26 @@ contexts.
 None
 ***
 
+## C++20 Allowed Language Features {#core-allowlist-20}
+
+### Designated initializers <sup>[allowed]</sup>
+
+```c++
+struct S { int x = 1; int y = 2; }
+S s{ .y = 3 };  // OK, s.x == 1, s.y == 3
+```
+
+**Description:** Allows explicit initialization of subsets of aggregate members
+at construction.
+
+**Documentation:**
+[Designated initializers](https://en.cppreference.com/w/cpp/language/aggregate_initialization#Designated_initializers)
+
+**Notes:**
+*** promo
+None
+***
+
 ## Abseil Banned Library Features {#absl-blocklist}
 
 The following Abseil library features are not allowed in the Chromium codebase.