I wonder if we should even get as far as producing that diagnostic in this case. The code is ill-formed: for a non-function friend declaration, 'friend' must be the first token in the declaration (see C++11 [class.friend]p3).<div>
<br></div><div><div>+  // Check whether the "friend" specifier is before or after the</div><div>+  // type specifiers to determine the highlighted range.</div><div>+  SourceRange HighlightRange = TypeRange.getEnd() < FriendLoc ?</div>
<div>+         SourceRange(TypeRange.getBegin(), PP.getLocForEndOfToken(FriendLoc)) :</div><div>+         SourceRange(FriendLoc, TypeRange.getEnd());</div></div><div><br></div><div>operator< on SourceLocation does not do what you expect here, and this doesn't form the correct range in cases where the 'friend' keyword is neither at the start nor at the end of the range, for instance "unsigned friend int;". How about just not including FriendLoc in the highlighted range at all? We're already pointing the caret at it.</div>
<div><br><div class="gmail_quote">On Wed, Aug 29, 2012 at 5:50 PM, Magee, Josh <span dir="ltr"><<a href="mailto:Joshua.Magee@am.sony.com" target="_blank">Joshua.Magee@am.sony.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
Attached is a patch to fix an assertion that occurs when printing diagnostic<br>
warnings for non-class friend usage.<br>
<br>
Example:<br>
This case prints fine:<br>
struct { friend int; } a;<br>
  warning: non-class friend type 'int' is a C++11 extension [-Wc++11-extensions]<br>
  friend int;<br>
  ^~~~~~~~~~<br>
<br>
This case causes an assertion:<br>
struct {int friend; } a;<br>
  warning: non-class friend type 'int' is a C++11 extension [-Wc++11-extensions]<br>
...<br>
Assertion `StartColNo <= EndColNo && "Invalid range!"' failed.<br>
<br>
The problem is that when printing the diagnostic the possibility that the<br>
friend specifier may appear after the type specifier is not considered.  The<br>
fix is to check whether the friend specifier appears after the type and adjust<br>
the highlight range accordingly.<br>
<br>
<br>
Can someone review and, if everything is OK, commit?<br>
<br>
Thanks!<br>
<span class="HOEnZb"><font color="#888888">Josh</font></span><br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div>