C++ Logo


Advanced search

Re: [std-proposals] scoped enums and varargs

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Sat, 24 Feb 2024 00:00:47 +0200
On Fri, 23 Feb 2024 at 23:51, enh via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> On Fri, Feb 23, 2024 at 1:45 PM Jonathan Wakely <cxx_at_[hidden]> wrote:
> >
> > On Fri, 23 Feb 2024 at 21:32, enh via Std-Proposals
> > <std-proposals_at_[hidden]> wrote:
> > >
> > > (https://isocpp.org/std/submit-issue led me to believe there isn't a
> > > public bug database, and i should send a mail here.)
> > >
> > > clang recently started warning about using scoped enums as arguments
> > > to varargs functions without a cast. this caused a lot of warning spam
> > > in Android, and a lot of confusion as to why there's even a warning
> > > here.
> >
> > Is this about varargs functions in general, or printf?
> printf() is the source of all the warnings i've seen.
> > I think it's intentional they don't promote when passed via varargs.
> > Why should you get implicit conversions from scoped enumeration types
> > when they don't implicitly convert under any other circumstances?
> because varargs seems like a special case...

I don't quite agree with that. It's functions categorically like
printf() that can be seen as the special
case, since such functions don't perform any real shenanigans, but
that doesn't apply to all
varargs functions. It would seem untoward if varargs functions are an
escape hatch for
the design intent of scoped enums not being implicitly convertible to
their underlying type.

> ...for this reason. in particular, it means you can't log a scoped
> enum's integer value for debugging without a cast that duplicates its
> underlying type (or arbitrarily picks a larger one).
> certainly everyone who wrote this code was expecting the usual
> promotions would apply (they've "correctly" used the appropriate
> format specifiers for if-i-passed-the-underlying-type-to-printf() in
> the cases i looked at).

Well, "usual promotions" _do_ apply. There are none for scoped enums.

Received on 2024-02-23 22:01:01