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

Frank Heckenbach <f.heckenb...@fh-soft.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |f.heckenb...@fh-soft.de

--- Comment #8 from Frank Heckenbach <f.heckenb...@fh-soft.de> ---
Some such cases, including the original example, will run afoul of aliasing
rules and at least produce a warning about that.

However, that's not the case when the target is char &, since char is
explicitly allowed to alias. So here's an example that doesn't produce any kind
of warning with any option I tried:

#include <iostream>

int main ()
{
  float x = 1.2345f;
  using T = char &;
  std::cout << +T (x);
}

It outputs 25 on x86_64 (LE) rather than 1 as with a value cast to char.

I agree that it may occur unnoticed in generic programming where a type
parameter may easily become of reference type.

I don't see any reason why someone would intentionally want to use this
"feature" -- if one wants a reinterpret cast, one should write
reinterpret_cast.

So I agree a warning would be very useful -- I'd even say it should be included
in -Wall or -Wextra if not on by default.

See also:
https://quuxplusone.github.io/blog/2020/01/22/expression-list-in-functional-cast/

Reply via email to