C++ Casting Error Messages

Hi all,

I was wondering what the wording of the error messages for C++ casts should be. Right now, I have them as:

t.cpp:
int volatile * const * ip;
float const * const * fpp = reinterpret_cast<float const * const *>(ip);
float const * volatile * fpv = reinterpret_cast<float const * volatile *>(ip);
float const * volatile * const * fpvc = reinterpret_cast<float const * volatile * const *>\
(ip);

$ clang -parse-ast-print t.cpp
t.cpp:2:29: error: reinterpret_cast from type 'int volatile *const *' to type 'float const\
*const *' casts away constness
float const * const * fpp = reinterpret_cast<float const * const *>(ip);
                             ^~~~~~~~~~~~~~~~
t.cpp:3:32: error: reinterpret_cast from type 'int volatile *const *' to type 'float const\
*volatile *' casts away constness
float const * volatile * fpv = reinterpret_cast<float const * volatile *>(ip);
                                ^~~~~~~~~~~~~~~~
What do you think?

-bw

Hi all,

I was wondering what the wording of the error messages for C++ casts
should be. Right now, I have them as:

t.cpp:
int volatile * const * ip;
float const * const * fpp = reinterpret_cast<float const * const *>(ip);
float const * volatile * fpv = reinterpret_cast<float const *
volatile *>(ip);
float const * volatile * const * fpvc = reinterpret_cast<float const

  • volatile * const *>
    (ip);

$ clang -parse-ast-print t.cpp
t.cpp:2:29: error: reinterpret_cast from type ‘int volatile *const *’
to type ‘float const
*const *’ casts away constness
float const * const * fpp = reinterpret_cast<float const * const *>(ip);
^~~~~~~~~~~~~~~~
t.cpp:3:32: error: reinterpret_cast from type ‘int volatile *const *’
to type ‘float const
*volatile *’ casts away constness
float const * volatile * fpv = reinterpret_cast<float const *
volatile *>(ip);
^~~~~~~~~~~~~~~~
What do you think?

Looks pretty good. Here is a diagnostic from the EDG compiler…

“ComeauTest.c”, line 2: error: reinterpret_cast cannot cast away const or other type qualifiers
float const * const * fpp = reinterpret_cast<float const * const *>(ip);
^

Here is a possible improvement that attempts to combine the best of both…

t.cpp:2:29: error: reinterpret_cast cannot cast away const or other type qualifiers from type ‘int volatile *const *’
float const * const * fpp = reinterpret_cast<float const * const *>(ip);
^~~~~~~~~~~~~~~~
snaroff