[cfe-dev] reinterpret_cast<int * const &>(array)

Eli Friedman eli.friedman at gmail.com
Mon Jun 11 16:17:35 PDT 2012


On Mon, Jun 11, 2012 at 3:05 PM, Jordan Rose <jordan_rose at apple.com> wrote:
> Hi, list. I came across this as an analyzer false positive, but as I read
> the C++ standard this is actually illegal. Can a standards expect weigh in
> here?
>
> void use(int *);
> void test() {
>   int x[8];
>   use(reinterpret_cast<int * const &>(x));
> }

"reinterpret_cast<int * const &>(x)" is roughly equivalent to
"*reinterpret_cast<int * const *>(&x)".  So test() is semantically
well-formed; it just has undefined behavior.

-Eli




More information about the cfe-dev mailing list