How to let C++ compiler raise a warning or error when a const is assigned to a const reference?
Miles Bader
miles@gnu.org
Mon Sep 18 23:09:00 GMT 2006
"Peng Yu" <pengyu.ut@gmail.com> writes:
> 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.
It's not "assigning a temp to a const reference" (that's done all the
time, and is perfectly innocent), it's "assigning a reference to a
variable with a certain extent to a reference with a longer-lived
extent." Does gcc have the information easily available to detect that?
-Miles
--
`...the Soviet Union was sliding in to an economic collapse so comprehensive
that in the end its factories produced not goods but bads: finished products
less valuable than the raw materials they were made from.' [The Economist]
More information about the Gcc-help
mailing list