[LLVMdev] Bogus warning?

Joerg Sonnenberger joerg at britannica.bec.de
Thu Jan 12 09:22:37 PST 2012


On Fri, Jan 13, 2012 at 02:13:46AM +0900, Brent Walker wrote:
> For the following (reduced) program:
> 
> bool f(double** x)
> {
>    const double *const *const p = x;
> 
>    return !p;
> }
> 
> Clang outputs the following warning:
> 
> warning: initializing 'const double *const *const' with an expression
> of type 'double **' discards qualifiers in nested pointer types
> [-Wincompatible-pointer-types]
> const double *const *const p = x;
> 
> I believe the code is correct.  Both gcc (-Wall) and the visual studio
> compiler compile the code without warnings.  I had to add an explicit
> cast to avoid the warning.
> 
> Should I be filling a bug report or is the warning legitimate?

The warning is legitimate, but slightly misleading. Basically, the
implicit const conversion only works on the outer pointer level.
So assigning foo * to const foo * is fine, but assign foo ** to const
foo ** is not. You should get a warning from GCC too --
"initialization from incompatible pointer type".

Joerg



More information about the llvm-dev mailing list