[cfe-commits] [PATCH 01/15] Fix Cast Code
Dmitri Gribenko
gribozavr at gmail.com
Thu Jan 10 12:04:34 PST 2013
On Thu, Jan 10, 2013 at 9:12 PM, David Greene <dag at cray.com> wrote:
> Fix casting to avoid cast-away-const errors.
ProtocolQualifiers = new Decl*[NP];
ProtocolLocs = new SourceLocation[NP];
- memcpy((void*)ProtocolQualifiers, Protos, sizeof(Decl*)*NP);
+ memcpy(const_cast<Decl **>(ProtocolQualifiers), Protos, sizeof(Decl*)*NP);
A better fix is to avoid a cast -- introduce a local variable of the
correct type and initialize it with new Decl*[NP] here, memcpy, and
assign to the data member after that.
Dmitri
--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
More information about the cfe-commits
mailing list