Boost C++ Libraries: Ticket #4527: warning in Boost.format and Boost.test C4224 https://svn.boost.org/trac10/ticket/4527 <p> Creates a blizzard of C2442 warnings when called from Boost.Test. </p> <p> I:\boost_1_43_0\boost/format/alt_sstream.hpp(128): warning C4224: nonstandard extension used : formal parameter 'arg' was previously defined as a type </p> <blockquote> <p> I:\boost_1_43_0\boost/format/alt_sstream.hpp(145) : see reference to class template instantiation 'boost::io::basic_oaltstringstream&lt;Ch,Tr,Alloc&gt;::No_Op' being compiled with [ </p> <blockquote> <p> Ch=char, Tr=std::char_traits&lt;char&gt;, Alloc=std::allocator&lt;char&gt; </p> </blockquote> <p> ] </p> </blockquote> <p> Problem is in class basic_oaltstringstream </p> <p> template&lt;class T&gt; </p> <blockquote> <p> const T &amp; operator()(const T &amp; arg) { return arg; } </p> </blockquote> <p> This trivial change of name from "arg" to "arg1" cures it. </p> <p> template&lt;class T&gt; const T &amp; operator()(const T &amp; arg1) { return arg1; } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4527 Trac 1.4.3 Steven Watanabe Wed, 11 Aug 2010 15:15:59 GMT <link>https://svn.boost.org/trac10/ticket/4527#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4527#comment:1</guid> <description> <p> Here's a smaller test case: </p> <pre class="wiki">#include &lt;boost/bind.hpp&gt; #include &lt;boost/format.hpp&gt; </pre><p> This produces warnings with /Za /W4 on MSVC 2008 and 2010. </p> <p> The problem reduces to </p> <pre class="wiki">namespace boost { template&lt;int I&gt; class arg {}; namespace io { class test { int operator()(const int &amp; arg) { return arg; } }; } } </pre><p> Frankly, this is just broken. I suggest that you just disable the warning or don't use /Za. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Paul A. Bristow</dc:creator> <pubDate>Fri, 13 Aug 2010 13:42:18 GMT</pubDate> <title>keywords changed https://svn.boost.org/trac10/ticket/4527#comment:2 https://svn.boost.org/trac10/ticket/4527#comment:2 <ul> <li><strong>keywords</strong> C4224 added; C2442 removed </li> </ul> <p> Well to the hapless Boost.Math library user who just wants a quick Student's t value and gets a faceful of warnings in a library (Boost.Format) he didn't even know he was using, it is certainly broken! </p> <p> I'm not a language lawyer or C++ style guru, but to reuse a name a bit gratuitously doesn't feel the best programming style ? </p> <p> It is even simpler than your test case </p> <pre class="wiki"> class arg {}; class test { int operator()(const int &amp; arg) { return arg; // Warning 4224 - argument arg same name as class arg. } }; class test_OK { int operator()(const int &amp; arg1) { return arg1; // OK argument has different name from class. } }; /* test_naming.cpp(5) : warning C4224: nonstandard extension used : formal parameter 'arg' was previously defined as a type Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0 */ </pre><p> I'm not clear what is the objection to the pragmatic simple change of name from 'arg' to anything else. </p> <p> Won't it get the problem out of our (and users) hair until MS (claiming it is an extension) and WG21 reach agreement if it is 'legal' or not? </p> Ticket Steven Watanabe Fri, 13 Aug 2010 17:33:33 GMT <link>https://svn.boost.org/trac10/ticket/4527#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4527#comment:3</guid> <description> <p> The code is perfectly fine. To see just how much code would have to be changed to avoid this warning entirely try running: </p> <pre class="wiki">grep -R -I --exclude-dir=.svn --exclude-dir=bind --exclude-dir=mpl '\barg\b' boost </pre><p> Reusing a name in this context is not a stylistic problem at all. The use of arg in Boost.Bind is totally irrelevant to Boost.Format. When I'm writing an argument name in my own member function in my own class in my own namespace, I don't want to have to worry about any other part of Boost. In order to prevent it we can't use any class name in any parent namespace as an argument name. This means that classes added in the global namespace (which we have no control over whatsoever) can trigger this warning in random parts of Boost. </p> <p> Also, /Za is not turned on by default anyway. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Paul A. Bristow</dc:creator> <pubDate>Tue, 17 Aug 2010 09:49:06 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4527#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4527#comment:4</guid> <description> <p> OK - instead of my sticking plaster fix, I have </p> <p> 1 'Complained' to Microsoft that this code is well-formed and should not trigger this warning, even with (no extensions) /Za option on. Long term this should cure this persistent problem. </p> <p> 2 Meanwhile, I have suppressed this warning in examples and tests that I am writing. </p> <blockquote class="citation"> <blockquote> <p> Also, /Za is not turned on by default anyway. </p> </blockquote> </blockquote> <p> But users who try (even if perhaps ineffectively) to attain strict standard compliance, should not be inconvenienced by a massive load of warning messages, or worse by a failure to compile if their policy is to treat warnings as errors. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Paul A. Bristow</dc:creator> <pubDate>Tue, 17 Aug 2010 09:49:58 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4527#comment:5 https://svn.boost.org/trac10/ticket/4527#comment:5 <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> Ticket Paul A. Bristow Fri, 27 Aug 2010 07:55:53 GMT <link>https://svn.boost.org/trac10/ticket/4527#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4527#comment:6</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/4527#comment:5" title="Comment 5">pbristow</a>: </p> <p> Microsoft Response </p> <p> Thank you for filing this issue. You are correct in that this is a bug in our compiler, however, there are some mitigating factors here. This warning is off-by-default in the compiler, and can only be turned on with /Wall (which is rare), or using /Za. And, as with all warnings, it is not an error unless combined with /WX (even under /Za) and can always be disabled with the compiler switch /wd or #pragma warning. Given these mitigating factors, we have prioritized this bug below more severe issues, and are not planning to fix this in our next release. </p> <p> Thank you for bringing this issue to our attention! </p> <p> Andy Rich Visual C++ QA </p> <p> <a class="ext-link" href="http://connect.microsoft.com/VisualStudio/feedback/details/586147/warning-c4224-is-given-for-correct-code-if-ms-extensions-are-disabled"><span class="icon">​</span>http://connect.microsoft.com/VisualStudio/feedback/details/586147/warning-c4224-is-given-for-correct-code-if-ms-extensions-are-disabled</a> </p> <p> I've replied 'thanks' ;-) </p> </description> <category>Ticket</category> </item> </channel> </rss>