Passing argv to loadFromCommandLine

I am attempting to call FixedCompilationDatabase::loadFromCommandLine. Seems pretty straight forward:

FixedCompilationDatabase::loadFromCommandLine(argc, argv);

In VS2013 this gives me an error:

cannot convert argument 2 from ‘char *’ to ‘const char **’

I am using the following signature of main (3.6.1/2 C++11 standard):

int main(int argc, char* argv)

It seems that the compiler should be able to do the conversion implicitly, but it isn’t. Is this how it is supposed to work? If it is, should the signature of loadFromCommandLine change so that argv can be passed directly?

Sounds like MSVC is worried you might store pointers to const char *'s into your argv array, and then it would lose const qualifiers. Clang gives a good diagnostic:

$ cat t.cpp

void f(const char **);
int main(int argc, char *argv) {
f(argv);
}

$ clang -c t.cpp
t.cpp:3:3: error: no matching function for call to ‘f’
f(argv);
^
t.cpp:1:6: note: candidate function not viable: no known conversion from ‘char **’ to ‘const char **’ for 1st argument
void f(const char **);
^

Maybe use ‘const char *argv’ if you don’t intend to modify argv?

The problem is that the standard only guarantees that int main(int argc, char argv[]) will be accepted as the signature of main. Yes, most compilers will accept anything that it can decay to const char* argv, but that is not guaranteed to work.

I often work with compilers that are of questionable quality (the joys of embedded systems). I don’t really trust them to follow the standard correctly, and I certainly don’t trust them to do something intuitive like allowing additional qualifiers on argv.

I was able to pass it the following way, but const_cast makes me cringe.

FixedCompilationDatabase::loadFromCommandLine(argc, const_cast<const char**>(argv))

I was able to pass it the following way, but const_cast makes me cringe.

FixedCompilationDatabase::loadFromCommandLine(argc, const_cast<const
char**>(argv))

I've committed a change in r235150 that should allow your original
code to work without the need for a const_cast.