[cfe-dev] Passing argv to loadFromCommandLine

Daniel Dilts diltsman at gmail.com
Wed Apr 15 15:32:12 PDT 2015


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.


On Wed, Apr 15, 2015 at 3:19 PM, Reid Kleckner <rnk at google.com> wrote:

> 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/77f914d2/attachment.html>


More information about the cfe-dev mailing list