[cfe-dev] Passing argv to loadFromCommandLine

Reid Kleckner rnk at google.com
Wed Apr 15 15:19:09 PDT 2015


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?

On Wed, Apr 15, 2015 at 2:37 PM, Daniel Dilts <diltsman at gmail.com> wrote:

> 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?
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150415/b8557637/attachment.html>


More information about the cfe-dev mailing list