https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82745

--- Comment #4 from helge at penne dot no ---
(In reply to Jonathan Wakely from comment #2)
> Narrowing conversions only cause a diagnostic in braced-init-list, not in
> other contexts. This is how C++ has worked since day one.

I must admit that I'm no compiler expert, nor do I have any deep knowledge of
the standard.  However, I think you must be mistaken here.

Try compiling the example I provided (with the command line options that I
specified).  If you compile it as-is it will pass, but if you remove the
comment to enable the last line (the one using unique_ptr instead of
make_unique) then it will issue a warning.  That line is not using
braced-init-list.

Btw. that line should probably ideally not have used auto and assignment, but
that should not affect the issue here.

The compiler will also correctly issue warnings about narrowing conversions on
assignment from a "wide" to a "narrow" integer type, including when the signs
don't match.  It will also warn when narrowing happens when passing parameters
to functions.

In fact, when enabled it warns about just about any narrowing conversion of
ints that I can think of, except those involving std::forward, hence the bug
report.

Please also have a look a the link I provided to the discussion on the
standards forum.  I believe these people know a thing or two, and some of them
were quite horrified that narrowing in std::forward did not result in a
warning.

Best regards,
H. Penne

Reply via email to