<div dir="ltr">Thank you everyone.<div><br></div><div>I knew about this difficulty in parsing, but did not realize it applied to this situation. Makes sense. Thanks!</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 26, 2015 at 12:17 AM, Gabriel Dos Reis <span dir="ltr"><<a href="mailto:gdr@integrable-solutions.net" target="_blank">gdr@integrable-solutions.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br><br>On Monday, May 25, 2015, Keno Fischer <<a href="mailto:kfischer@college.harvard.edu" target="_blank">kfischer@college.harvard.edu</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi folks,<div><br></div><div>I'm confused by the following code snippet:</div><div><br></div><div><div>#include <memory></div><div>void foo(int *x) { std::unique_ptr<int>(x); }</div></div><div><br></div><div>both clang and gcc warn that this redefines x, but I don't understand why this</div><div>is a declaration of x. I guess I would have expected a temporary unique_ptr that gets destructed immediately or an error. How come this actually defines a variable called x?</div></div></blockquote><div><br></div></span><div>The C and C++ grammars allow redundant parenthesis around names being declared (technically, declarators). </div><div>If you wish to construct a temporary, use the brace notation, aka uniform initialization syntax.</div><div class="HOEnZb"><div class="h5"><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>To give some background about where this came up, a user wanted to do</div><div>C++> std::unique_ptr<int>(x);</div><div>in my Clang-based interactive C++ REPL. Behind the scenes this gets transformed into the function above and then I try to insert a return statement on the last statement in the body to automatically grab the result. This works well in most cases but failed here because Clang thinks this is a variable declaration, so I'd like to understand why this is happening.</div><div><br></div><div>Keno</div></div>
</blockquote>
</div></div></blockquote></div><br></div>