Attached is a new patch that (a) fixes the assertion when emitting the warning dialogue in C++98 mode, and (b) implements C++11 [class.friend]p3 (PR9834).
For (a) I removed FriendLoc from the highlight range. As noted, the caret is pointing to FriendLoc anyway. For (b): During parsing, I flagged whether or not the friend keyword appears first in friend declarations. Unfortunately, since the standard only requires friend to be the first token in non-function friend declarations, it isn't possible to generate an error at this point. Instead, in Semantic Analysis, generate an error if the FriendFirst flag is not set when checking a friend type (i.e., non-function) declaration. Thanks, Josh At 1346342316 seconds past the Epoch, Richard Smith wrote: > 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). > > + // Check whether the "friend" specifier is before or after the > + // type specifiers to determine the highlighted range. > + SourceRange HighlightRange = TypeRange.getEnd() < FriendLoc ? > + SourceRange(TypeRange.getBegin(), > PP.getLocForEndOfToken(FriendLoc)) : > + SourceRange(FriendLoc, TypeRange.getEnd()); > > 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. > > On Wed, Aug 29, 2012 at 5:50 PM, Magee, Josh <[email protected]>wrote: > > > Hi, > > > > Attached is a patch to fix an assertion that occurs when printing > > diagnostic > > warnings for non-class friend usage. > > > > Example: > > This case prints fine: > > struct { friend int; } a; > > warning: non-class friend type 'int' is a C++11 extension > > [-Wc++11-extensions] > > friend int; > > ^~~~~~~~~~ > > > > This case causes an assertion: > > struct {int friend; } a; > > warning: non-class friend type 'int' is a C++11 extension > > [-Wc++11-extensions] > > ... > > Assertion `StartColNo <= EndColNo && "Invalid range!"' failed. > > > > The problem is that when printing the diagnostic the possibility that the > > friend specifier may appear after the type specifier is not considered. > > The > > fix is to check whether the friend specifier appears after the type and > > adjust > > the highlight range accordingly. > > > > > > Can someone review and, if everything is OK, commit? > > > > Thanks! > > Josh > > _______________________________________________ > > cfe-commits mailing list > > [email protected] > > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits > > > >
friends-first.diff
Description: friends-first.diff
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
