[PATCH] D90188: Add support for attribute 'using_if_exists'

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 4 08:30:28 PST 2020


aaron.ballman added inline comments.


================
Comment at: clang/include/clang/AST/DeclCXX.h:3801
+/// error.
+class UnresolvedUsingIfExistsDecl final : public NamedDecl {
+  UnresolvedUsingIfExistsDecl(DeclContext *DC, SourceLocation Loc,
----------------
erik.pilkington wrote:
> aaron.ballman wrote:
> > erik.pilkington wrote:
> > > aaron.ballman wrote:
> > > > Why is this inheriting from a `NamedDecl` rather than a `UsingDecl`? Given that this is a type of using declaration, I guess I would have expected it to appear as such in the AST hierarchy. For instance, should people using AST matchers be able to match one of these as a using declaration or are they so different semantically that they need to be sibling AST nodes?
> > > This node isn't a kind of using declaration, it is a declaration that gets inserted into the scope via a usual UsingDecl & UsingShadowDecl mechanism that Sema knows to error out on if it is ever used. So presumably existing AST users would still recognize that this is a UsingDecl that adds a single declaration into the current context, but wouldn't really know anything about that declaration. I updated the doc comment above to make that more clear.
> > So given code like this:
> > ```
> > using empty_namespace::does_not_exist __attribute__((using_if_exists)); 
> > ```
> > would you expect this AST matcher to match or not?
> > ```
> > usingDecl()
> > ```
> > (I hope the answer is "yes" because otherwise the behavior is rather inexplicable to me.)
> Yeah, the answer is "yes". The AST representation for a using_if_exists declaration that failed to lookup anything would look something like this:
> 
> ```
> |-UsingDecl 0x7fa42b84a3a0 <t.cpp:20:1, col:9> col:9 ::X
> |-UsingShadowDecl 0x7fa42b84a3f8 <col:9> col:9 implicit UnresolvedUsingIfExists 0x7fa42b84a370 'X'
> ```
> 
> So its still using the typical UsingDecl machinery, its just that the declaration thats being imported is different.
Awesome, thank you for clarifying!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90188/new/

https://reviews.llvm.org/D90188



More information about the cfe-commits mailing list