[PATCH] Location and Range unittests for FriendDecl
Nikola Smiljanić
popizdeh at gmail.com
Mon Jun 30 22:52:14 PDT 2014
================
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?
```
#define DECL void f();
struct A{
friend DECL
};
```
http://reviews.llvm.org/D3906
More information about the cfe-commits
mailing list