Re: How to let C++ compiler raise a warning or error when a const is assigned to a const reference?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Please do not cross-post to both gcc-help and gcc.

I don't remember I post the message to both gcc-help and gcc.

I believe your code is legal code.

It's not code that does what you want, but it is code that is doing what you told it to do.

Keep in mind, warnings are indicators that the compiler has discovered something suspect -- something that MAY BE an error and is something that people either do often enough (inadvertently) or is generally considered bad programming practice to warrant a warning (perhaps even being a recommended warning by ISO 14882).

I think the compiler should suspect there is something wrong, because
the buggy code assigns the reference of a temp variable to a const
reference. It should be that a const reference be assigned to another
const reference.

My guess is, the situation you cited does not come up often in practice to have caused one of the GCC developers to put a warning into GCC.

If you doing template metaprogramming, you'll see this situation
sometimes. Adding a warning will help the programmer using this
technique.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux