[PATCH] Location and Range unittests for FriendDecl

Richard Smith richard at metafoo.co.uk
Wed Jul 16 16:23:38 PDT 2014


On Mon, Jun 30, 2014 at 10:52 PM, Nikola Smiljanić <popizdeh at gmail.com>
wrote:

> ================
> Comment at: include/clang/AST/DeclFriend.h:148
> @@ +147,3 @@
> +      SourceLocation DeclLoc = ND->getLocStart();
> +      return SourceRange(FriendLoc < DeclLoc ? FriendLoc : DeclLoc,
> +                         ND->getLocEnd());
> ----------------
> Richard Smith wrote:
> > This use of `<` is not correct (it'll do the wrong thing in the presence
> of macro expansion). `SourceManager::isBeforeInTranslationUnit` is the
> right way, but it's hard to get at from here. What does a `friend` function
> declaration think its `LocStart` is? Does that include the `friend` token
> already? Maybe you can just use that.
> This is very unfortunate but getStartLoc depends on the range, it's
> whatever beginning of the range is :(
>
> Note that we need this only for that contrived case of yours ;) where
> friend isn't the first token in the declaration. What's worse, having wrong
> range in that case or in the presence of macro expansion? Who uses macros
> anyway :P
>
> I tried this but friend keyword and start of NamedDecl point to same
> location. Could we already be wrong in this case?
>

If the start of the `FunctionDecl` already points to the `friend` keyword,
then we should be able to use `DeclLoc` in all cases.


>
> ```
> #define DECL void f();
> struct A{
>   friend DECL
> };
> ```
>
> http://reviews.llvm.org/D3906
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140716/dd6d5294/attachment.html>


More information about the cfe-commits mailing list