[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [patch][c++] fix "invalid conversion from ‘void*’ to ‘char*’"
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 27 Jun 2016 12:36:01 -0300
> > It was thus said that the Great Irfan Adilovic once stated:
> > > In the 5.3.3 release, lua/lstrlib.cc:936:
> > >
> > > char *ppoint = memchr(buff, point, nb);
> > >
> > > is not valid c++ code. This should be fixed with a c-style cast:
> > But it *is* valid C code. In C, it's recommended *not* to cast the result
> > of malloc() as it can hide errors (mainly missing declarations---in C,
> > without a prototype, the compiler will assume a function returns an int).
> We always use -Wmissing-prototypes, so this does not seem to be an
> issue. Note that Lua already casts all the result of malloc (see macros
> in 'lmem.h')---otherwise there would be lots of errors like this one.
BTW, we always use -Wmissing-prototypes plus -Wstrict-prototypes and
-Wold-style-definition and -Wc++-compat. This last one should have
warned us about this particular problem:
-Wc++-compat (C and Objective-C only)
Warn about ISO C constructs that are outside of the common subset
of ISO C and ISO C++, e.g. request for implicit conversion from
"void *" to a pointer to non-"void" type.
gcc correctly flags this problem, but clang does not, even though
it gladly accepts the option. (We have been using clang lately, and
we apparently failed to check 5.3.3 releases with gcc...)