<div dir="ltr"><div>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.</div><div><br></div><div>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.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 15, 2015 at 3:19 PM, Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">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:<div><br><div>$ cat t.cpp</div><div><div>void f(const char **);</div><div>int main(int argc, char *argv[]) {</div><div> f(argv);</div><div>}</div></div><div><br></div><div><div>$ clang -c t.cpp</div><div>t.cpp:3:3: error: no matching function for call to 'f'</div><div> f(argv);</div><div> ^</div><div>t.cpp:1:6: note: candidate function not viable: no known conversion from 'char **' to 'const char **' for 1st argument</div><div>void f(const char **);</div><div> ^</div></div></div><div><br></div><div>Maybe use 'const char *argv[]' if you don't intend to modify argv?<br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Wed, Apr 15, 2015 at 2:37 PM, Daniel Dilts <span dir="ltr"><<a href="mailto:diltsman@gmail.com" target="_blank">diltsman@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div><div class="h5"><div dir="ltr"><div>I am attempting to call FixedCompilationDatabase::loadFromCommandLine. Seems pretty straight forward:</div><div><br></div><div>FixedCompilationDatabase::loadFromCommandLine(argc, argv);</div><div><br></div><div>In VS2013 this gives me an error:</div><div><br></div><div>cannot convert argument 2 from 'char *[]' to 'const char **'</div><div><br></div><div>I am using the following signature of main (3.6.1/2 C++11 standard):</div><div><br></div><div>int main(int argc, char* argv[])</div><div><br></div><div>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?</div></div>
<br></div></div>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>