<br><br><div class="gmail_quote">On Tue, Sep 20, 2011 at 10:33 PM, Eli Friedman <span dir="ltr"><<a href="mailto:eli.friedman@gmail.com">eli.friedman@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><div></div><div class="h5">On Tue, Sep 20, 2011 at 10:01 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
> I was mucking about with typeof (discovered it looking at DeclSpecs various<br>
> SourceLocation information trying to piece together SourceLocations/Ranges<br>
> covering the entire return type both before & after the identifier) & I<br>
> discovered this curious behavior:<br>
> Given this:<br>
>     int i = 3;<br>
>     typeof(i) (*foo())() {<br>
>     }<br>
> The following output is provided<br>
><br>
>   typeof.cpp:2:13: error: use of undeclared identifier 'foo'<br>
>   typeof(i) (*foo())()<br>
>               ^<br>
>   typeof.cc:4:2: error: expected unqualified-id<br>
>   }<br>
>    ^<br>
><br>
> If I use a simple function (typeof(i) foo() {}) it compiles fine. If I use<br>
> gcc/g++ I get a very similar error to the one clang provides. So it's at<br>
> least bug-for-bug compatible, but I'm wondering what the desired behavior is<br>
> here & why this case would be failing in the way it is.<br>
> Interestingly, C++0x's decltype works totally fine here (ie: compiles<br>
> without error). So I'm wondering: in what way is typeof not just an alias<br>
> for decltype? Should it be? (could we remove some redundant code in clang by<br>
> coalescing these two cases together) Or is there some legitimate reason for<br>
> these errors.<br>
<br>
</div></div>The grammar of typeof in C++ is "typeof unary-expression".  Note the<br>
lack of parentheses in this production.  Granted, it isn't<br>
particularly sane, which is why decltype is not defined that way.<font class="Apple-style-span" color="#888888"><br></font></blockquote></div><br><div>Hmm, that is rather cunning (& not at all clear from the simple examples on the GNU documentation page for the feature <a href="http://gcc.gnu.org/onlinedocs/gcc/Typeof.html">http://gcc.gnu.org/onlinedocs/gcc/Typeof.html</a> ). So it was parsing my expression as:</div>
<div><br></div><div>    typeof ((y) (*x)()) <br><br></div><div>basically. Which could be valid if y was something callable (with the result of unary* on x), that when called was itself callable (with no args). Yeah, that's got to be rather annoying to parse/deal with.</div>
<div><br></div><div>Thanks Eli,</div><div><br></div><div>- David<br><br><br></div>