<div class="gmail_quote">On Fri, Aug 10, 2012 at 1:47 PM, Артем Зуйков <span dir="ltr"><<a href="mailto:chertus@gmail.com" target="_blank">chertus@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>Hi,</div><div><br></div><div>What do you think about this code and clang reaction?</div><div><br></div><div>struct A<br>{<br> static const char * a;<br>};<br><br>const char * A::a = "O.o";<br><br>struct B<br>
{<br> B(const char * s);<br>};<br><br>struct C<br>{<br> C(B& b);<br>};<br><br>class Problem<br>{<br>public:<br> void foo()<br> {<br> C c(B(A::a)); // error here<br> }<br>};</div><div><br></div><div><br>
</div><div>> clang++ x.cpp<br>x.cpp:23:6: warning: parentheses were disambiguated as a function declarator<br> [-Wvexing-parse]<br> C c(B(A::a)); // error here<br> ^~~~~~~~~<br>x.cpp:23:12: error: parameter declarator cannot be qualified<br>
C c(B(A::a)); // error here<br> ~~~^<br>1 warning and 1 error generated.</div></blockquote><div><br></div><div>The error looks correct to me. This line conforms to the grammar rules of a function-declaration, so it is interpreted as one. The diagnostic on trunk is a bit better:</div>
<div><br></div><div> <stdin>:23:15: error: parameter declarator cannot be qualified</div><div> C c(B(A::a)); // error here</div><div> ~~~^</div><div><stdin>:23:9: warning: parentheses were disambiguated as a function declaration [-Wvexing-parse]</div>
<div> C c(B(A::a)); // error here</div><div> ^~~~~~~~~</div><div><stdin>:23:10: note: add a pair of parentheses to declare a variable</div><div> C c(B(A::a)); // error here</div><div> ^</div><div>
( )</div><div><div>1 warning and 1 error generated.</div></div><div><br></div><div>... though perhaps we should detect this case and give a more specific error message.</div></div>