Do we allow Designated initializers in C++20?

149 views
Skip to first unread message

Leo Lai

unread,
Feb 4, 2021, 11:45:45 PM2/4/21
to c...@chromium.org, Maksim Ivanov
Hello, team:

Background:
I had a CL where I used Designated initializers, and +Maksim Ivanov  reminded me that the feature is not allowed per chromium C++ standard doc because it's per C++20.
Then, I found there are many uses of the feature already, with a roughly accurate grepping function git grep -nE " \.[A-z]* = " |grep -E "\.(cc|h)\b:" and i got thousands of lines. 
Looks like "Designated initializers" is getting widely adopted in chromium project, despite of the fact that we don't officially support it at this moment.

Question:
Is there any plan to officially claim it is allowed or disallowed to use Designated initializers?

Thanks!

--

Leo Lai | Software Engineer | cy...@google.com | +886-905-902-069

Daniel Cheng

unread,
Feb 4, 2021, 11:58:37 PM2/4/21
to Leo Lai, cxx, Maksim Ivanov
We started allowing it when the upstream styleguide was updated. See https://groups.google.com/a/chromium.org/g/cxx/c/1-rY_Zo7g8w/m/y5q8mQSQAwAJ for the discussion.


The important part is this:

Use designated initializers only in the form that is compatible with the draft C++20 standard: with initializers in the same order as the corresponding fields appear in the struct definition.

Daniel

--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAE4dLq9F9Zt_rRZ4Cps99ntfTe7QuQkMkiMEH9aLwv0Q6c-PpA%40mail.gmail.com.

Avi Drissman

unread,
Feb 5, 2021, 12:42:35 AM2/5/21
to Daniel Cheng, Leo Lai, cxx, Maksim Ivanov
IMO we then should update http://chromium-cpp.appspot.com/ to be consistent with that decision. That site is the official reference of "can we use this C++ feature in Chromium" and as this is explicitly allowed from C++20 while all of C++17 isn't allowed, it should be noted.

dan...@chromium.org

unread,
Feb 5, 2021, 10:47:27 AM2/5/21
to Avi Drissman, Daniel Cheng, Leo Lai, cxx, Maksim Ivanov
On Fri, Feb 5, 2021 at 12:42 AM Avi Drissman <a...@chromium.org> wrote:
IMO we then should update http://chromium-cpp.appspot.com/ to be consistent with that decision. That site is the official reference of "can we use this C++ feature in Chromium" and as this is explicitly allowed from C++20 while all of C++17 isn't allowed, it should be noted.

That site has become a list of what is _not_ allowed now, since the list of what is allowed became quite large. And notably designated initializers are not mentioned (unless my search skills are bad).
 

Maksim Ivanov

unread,
Feb 5, 2021, 10:55:32 AM2/5/21
to dan...@chromium.org, Avi Drissman, Daniel Cheng, Leo Lai, cxx
I parse that site differently. It says:
"C++14: Default allowed"
"C++17: Not yet supported in Chromium"
"C++20: Not yet standardized"

There's also a link from that site to crbug.com/752720 about C++17 support in Chromium, and the bug is still open.

Therefore I was interpreting it as "only <=C++14 is allowed, and anything newer is forbidden". So +1 to Avi's suggestion to clarify the site if the actual intention is the opposite - I find the current description quite ambiguous.


Maksim

K. Moon

unread,
Feb 5, 2021, 11:03:10 AM2/5/21
to Maksim Ivanov, danakj chromium, Avi Drissman, Daniel Cheng, Leo Lai, cxx
The way I view the various style documents we have:
  1. The Google style guide is authoritative, unless explicitly contradicted.
  2. The Chromium style guide is authoritative.
  3. chromium-cpp.appspot.com is part of the Chromium style guide. 
  4. The dos and don'ts page is advice.
Now, the way I read the style guides here is that the Google guide isi not allowing "C++20 designators" so much as "common pre-C++20 extension designators," and adding the further restriction, "Must be compatible with future support for C++20 designators." Subtle, but doesn't contradict our local stipulation against C++17 and C++20 features.

If it's confusing to a lot of people, though, I don't think a point of clarification would hurt.

dan...@chromium.org

unread,
Feb 5, 2021, 11:25:46 AM2/5/21
to K. Moon, Maksim Ivanov, Avi Drissman, Daniel Cheng, Leo Lai, cxx
On Fri, Feb 5, 2021 at 11:03 AM K. Moon <km...@chromium.org> wrote:
The way I view the various style documents we have:
  1. The Google style guide is authoritative, unless explicitly contradicted.
  2. The Chromium style guide is authoritative.
  3. chromium-cpp.appspot.com is part of the Chromium style guide. 
  4. The dos and don'ts page is advice.
Now, the way I read the style guides here is that the Google guide isi not allowing "C++20 designators" so much as "common pre-C++20 extension designators," and adding the further restriction, "Must be compatible with future support for C++20 designators." Subtle, but doesn't contradict our local stipulation against C++17 and C++20 features.

If it's confusing to a lot of people, though, I don't think a point of clarification would hurt.

That's fair. Im happy to review a fix for the page!

 

Maksim Ivanov

unread,
Feb 15, 2021, 6:25:23 PM2/15/21
to dan...@chromium.org, K. Moon, Avi Drissman, Daniel Cheng, Leo Lai, cxx
Hi,

I'm happy to create the CL, but for this I'd need to understand what exactly are we allowing:

(a) any feature, allowed by the Google style guide, which exists as a compiler extension that's turned on in the C++14 mode and is compatible with all officially supported Chromium build configurations;
(b) only designated initializers?

(Like, the designated initializers are currently working in clang in Chrome because they're implemented as a C++20 extension (formerly C99 extension) - this can be verified by a warning generated when the "-pedantic" compiler flag is added.)

Obviously, "(b)" is the simplest to write.
As for "(a)" - it avoids special-casing, since, if I understand the earlier responses correctly, any language feature with similar properties would be allowed as well?..

Do we have other examples besides designated initializers that are already allowed today despite being > C++14?
As a random example, I found that the C++17 hexadecimal floating-point literals work in our clang without any warnings (both in the regular clang in the C++14 mode and in the NaCl toolchain) - does that qualify for usage in Chromium? (there even seems to be a potential use case for them: source.chromium.org/chromium/chromium/src/+/master:v8/src/base/ieee754.cc;l=2305;drc=c512d6173f33c6b8301d3fba9384edc9fc1f9e45)


Maksim

Peter Kasting

unread,
Feb 15, 2021, 9:36:28 PM2/15/21
to Maksim Ivanov, dan...@chromium.org, K. Moon, Avi Drissman, Daniel Cheng, Leo Lai, cxx
The intent of past styleguide discussions was (b).

PK

K. Moon

unread,
Feb 16, 2021, 3:20:11 PM2/16/21
to Peter Kasting, Maksim Ivanov, danakj chromium, Avi Drissman, Daniel Cheng, Leo Lai, cxx
I would also add that the Google C++ style guide only calls out designated initializers for special treatment with respect to extensions, so there are no other features that (a) should apply to.
Reply all
Reply to author
Forward
0 new messages