Boost C++ Libraries: Ticket #3909: parse_command_line has bad declaration https://svn.boost.org/trac10/ticket/3909 <p> The parse_command_line must receive const char* const argv[]. </p> <p> Change: </p> <div class="wiki-code"><div class="code"><pre><span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">charT</span><span class="o">&gt;</span> <span class="n">basic_parsed_options</span><span class="o">&lt;</span><span class="n">charT</span><span class="o">&gt;</span> <span class="n">parse_command_line</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="n">charT</span><span class="o">*</span> <span class="err">&#39;</span><span class="k">const</span><span class="err">&#39;</span> <span class="n">argv</span><span class="p">[],</span> <span class="p">....)</span> </pre></div></div> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3909 Trac 1.4.3 anonymous Mon, 08 Feb 2010 11:28:09 GMT <link>https://svn.boost.org/trac10/ticket/3909#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3909#comment:1</guid> <description> <p> Also there is a problem with constness in charT. </p> <p> This causes problem: </p> <div class="wiki-code"><div class="code"><pre><span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="k">const</span><span class="o">*</span> <span class="k">const</span> <span class="n">argv</span><span class="p">[])</span> <span class="p">{</span> <span class="n">parse_command_line</span><span class="p">(</span><span class="n">argc</span><span class="p">,</span> <span class="n">argv</span><span class="p">);</span> <span class="p">}</span> </pre></div></div><ol><li>parse_command_line cannot receive char const* const<br /> </li><li>charT = char const , there is no specialization for basic_parsed_options&lt;char const&gt; So there is a need to remove_cv&lt;charT&gt; and only then specialize basic_parsed_options. </li></ol><p> <br /> </p> <div class="wiki-code"><div class="code"><pre><span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">charT</span><span class="o">&gt;</span> <span class="n">basic_parsed_options</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">remove_cv</span><span class="o">&lt;</span><span class="n">charT</span><span class="o">&gt;::</span><span class="n">type</span><span class="o">&gt;</span> <span class="n">parse_command_line</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="n">charT</span><span class="o">*</span> <span class="k">const</span> <span class="n">argv</span><span class="p">[],</span> <span class="p">....)</span> </pre></div></div> </description> <category>Ticket</category> </item> <item> <dc:creator>vladimir</dc:creator> <pubDate>Mon, 08 Feb 2010 12:42:34 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3909#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3909#comment:2</guid> <description> <p> Could you clarify? The type of argv you use in your example is in violation of the C++ standard, I believe. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 08 Feb 2010 15:05:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3909#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3909#comment:3</guid> <description> <p> I am not sure about violation because adding const does not destroy anything. But the Standard says about int main(int argc, char* argv[]), so from this point of view you are right. </p> <p> Anyway I don't know if there is a compiler which rejects main function with char const* const argv[]. Event Comeau compiler accepts it. </p> <p> I suggest you to add remove_cv anyway, it will make code more correct. Thank you. </p> </description> <category>Ticket</category> </item> <item> <author>ilyasokol@…</author> <pubDate>Mon, 24 May 2010 12:16:10 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3909#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3909#comment:4</guid> <description> <p> See these use cases: </p> <p> <a class="ext-link" href="http://lists.boost.org/boost-users/2006/01/16620.php"><span class="icon">​</span>http://lists.boost.org/boost-users/2006/01/16620.php</a> <a class="ext-link" href="http://lists.boost.org/boost-users/2009/08/50968.php"><span class="icon">​</span>http://lists.boost.org/boost-users/2009/08/50968.php</a> </p> <p> The signature can be changed as follows: </p> <pre class="wiki">template&lt;class charT&gt; basic_parsed_options&lt;typename remove_cv&lt;charT&gt;::type&gt; parse_command_line(int argc, const charT* const argv[], ....) or template&lt;class charT&gt; basic_parsed_options&lt;typename remove_cv&lt;charT&gt;::type&gt; parse_command_line(int argc, const charT* const* argv, ....) </pre><p> (The second is a bit more readable for me) </p> <p> There is no need to remove_cv&lt;charT&gt; and the change is fully backward compatible. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Wed, 01 Dec 2010 18:54:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3909#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3909#comment:5</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/66959" title="Take argv as const; refs #3909">[66959]</a>) Take argv as const; refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3909" title="#3909: Bugs: parse_command_line has bad declaration (closed: fixed)">#3909</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Sat, 04 Dec 2010 17:39:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3909#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3909#comment:6</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/67006" title="patch tests for Sun; refs #3909">[67006]</a>) patch tests for Sun; refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3909" title="#3909: Bugs: parse_command_line has bad declaration (closed: fixed)">#3909</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Sat, 25 Dec 2010 11:33:12 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/3909#comment:7 https://svn.boost.org/trac10/ticket/3909#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> I assume this is fixed by earlier commits. Thanks Marshall! </p> Ticket