Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Proposal: Allow `using enum`

57 views
Skip to first unread message

Christoph Schwering

unread,
Oct 17, 2024, 12:17:42 PM10/17/24
to cxx
I propose to allow C++20 `using enum` (modulo the style guide's general restrictions of aliases).

Advantages: much reduced noise, for example, in switch statements. Grep [1] suggests that 34% of our enums type names have 20 or more characters (the winner has 58 :)).

Disadvantage: higher risk of naming collisions, especially with `kMaxValue`, when the scope is too large.

The repository already contains 161 occurrences of `using enum`, but as Maksim pointed out to me, it's not listed in c++features.md

[1] git grep -oE 'enum\sclass\s\w+\s' | sed 's/^.*enum\sclass\s//' | awk '{ print length, $0 }' | sort -n

danakj

unread,
Oct 17, 2024, 1:40:24 PM10/17/24
to Christoph Schwering, cxx
+1

--
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/CAN-ZcvFYX3oQr7tYBCjCxJW4puru3NeE_i3Akz_wa419C9zEtA%40mail.gmail.com.

Avi Drissman

unread,
Oct 17, 2024, 2:12:12 PM10/17/24
to Christoph Schwering, cxx
I'm a +1 to this. This helps in readability a lot, and I don't see the downsides as being especially meaningful.

Avi

--

Peter Kasting

unread,
Oct 17, 2024, 2:23:13 PM10/17/24
to Christoph Schwering, cxx
I had assumed this was tacitly allowed and guided by the style guide's wording around aliases. If you think it's not clearly so, I support adding it to the allowed language features section of the doc. 

PK

--

John Admanski

unread,
Oct 17, 2024, 2:28:24 PM10/17/24
to Peter Kasting, Christoph Schwering, cxx
I think there's a bit of a desync due to the fact that the Chromium style guide uses the Google style guide as a base, but the Google style guide does not follow the "default allow only after 2 years" restriction that Chromium also has for new language features. So things can make it into the style guide without coming off the C++20 TBD list.

Peter Kasting

unread,
Oct 17, 2024, 2:32:38 PM10/17/24
to John Admanski, Christoph Schwering, cxx
To be clear, that two year threshold is not yet past for c++20. I was saying I think the _Google_ style guide already intends this to be allowed under the same guidance as other using declarations.

PK

Maksim Ivanov

unread,
Oct 17, 2024, 3:47:37 PM10/17/24
to Peter Kasting, John Admanski, Christoph Schwering, cxx
Thanks for starting the conversation, Christoph.

I guess the unclear part for me is the "C++20 Allowed Language Features" section in Chromium's style guide, if the actual idea is that anything allowed by the Google Style Guide is implicitly allowed as well. E.g., Chromium's guide explicitly mentions consteval as allowed, but it's already mentioned in Google Style Guide?.. And if we use implicit assumptions about inheriting C++20 rules between guidelines, then Google Style Guide just says targeting C++20?.. I'd appreciate it if these aspects would be clarified more explicitly. Thanks!


Peter Kasting

unread,
Oct 17, 2024, 4:00:52 PM10/17/24
to Maksim Ivanov, John Admanski, Christoph Schwering, cxx
On Thu, Oct 17, 2024 at 12:47 PM Maksim Ivanov <em...@chromium.org> wrote:
Thanks for starting the conversation, Christoph.

I guess the unclear part for me is the "C++20 Allowed Language Features" section in Chromium's style guide, if the actual idea is that anything allowed by the Google Style Guide is implicitly allowed as well. E.g., Chromium's guide explicitly mentions consteval as allowed, but it's already mentioned in Google Style Guide?.. And if we use implicit assumptions about inheriting C++20 rules between guidelines, then Google Style Guide just says targeting C++20?.. I'd appreciate it if these aspects would be clarified more explicitly. Thanks!

The core issue is that I added the list of features to be considered based on a couple of reference sources, and none of them had called this out as a high-level bullet, so it didn't get listed. I didn't even know the syntax was C++20; I had assumed this was already available in C++17.

So it's an oversight in list construction, or "too minor a feature to bother actually listing", depending on which way you want to interpret it. In either case, we should resolve ambiguity by just going ahead and listing it as allowed.

PK

Peter Kasting

unread,
Oct 17, 2024, 7:05:15 PM10/17/24
to cxx, Peter Kasting, John Admanski, schw...@google.com, cxx, Maksim Ivanov
On Thursday, October 17, 2024 at 1:00:52 PM UTC-7 Peter Kasting wrote:
So it's an oversight in list construction, or "too minor a feature to bother actually listing", depending on which way you want to interpret it. In either case, we should resolve ambiguity by just going ahead and listing it as allowed.

(FYI I have sent https://chromium-review.googlesource.com/c/chromium/src/+/5941512 to correct this, so this will be "allowed soon".)

PK 

Maksim Ivanov

unread,
Oct 17, 2024, 7:49:47 PM10/17/24
to Peter Kasting, cxx, John Admanski, schw...@google.com
Thanks!
Reply all
Reply to author
Forward
0 new messages