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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
No, because a (T) style cast can do almost anything. In this case it's
equivalent to

const_cast<std::string&>(static_cast<const std::string&>(a->m_i))

which is valid code.

-Wold-style-cast will warn about using any form of (T) cast, which can
encourage you to be more careful and precise about what you're trying to do.

If you had written it like this:

std::cout << static_cast<std::string&>(a->m_i) << std::endl;

Then it wouldn't even compile.

tl;dr don't use C-style casts if you want the compiler to tell you when you're
doing something wrong.

Reply via email to