2010/10/12 Ian Lance Taylor <iant@xxxxxxxxxx>: > Jens Rehsack <rehsack@xxxxxxxxxxxxxx> writes: > >> I currently write some c++ code using libConfuse >> (http://savannah.nongnu.org/projects/confuse/). >> During initialisation of the required cfg_opt_t structures I get a >> (very) lot of warnings like: >> c2.cpp:11: warning: deprecated conversion from string constant to ‘char*' >> >> I attached a small example to demonstrate the problem. It's not >> trivial - changing the "name" member >> of struct demo being const, free failes (and is invalid, because >> there're demo_opt instances with >> modifyable names). >> >> Any suggestions welcome. >> 1) Killing the warning with -Wno-... is not an option >> 2) Remove the finding using const_cast<char *>() is the same as (1) >> 3) initializing the struct using strdup is neither reasonable > > I'm not sure what you want us to suggest. You say that the names are > modifiable. Where do I say that? I apologize saying this (must be happened because of my not so good english). > String constants are not modifiable. If the strings are > indeed modified, and you pass in a string constant, then your program is > going to crash when the library tries to modify the strings. The gcc > warning is helpfully pointing that out. Correct. And if the strings are not modifiable? (I thought I provided an example which shows, that they neither are assumed being modifiable nor being modified). > This is not a gcc issue. It's a C++ language issue. If you need a > modifiable string, then you must not use a string constant. How can this being expressed without declaring dozen of helper variables? /Jens