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

Erik Pilkington via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 26 13:19:01 PDT 2020


erik.pilkington created this revision.
erik.pilkington added reviewers: rsmith, aaron.ballman, ldionne.
Herald added subscribers: dexonsmith, ributzka, arphaman, jkorous.
erik.pilkington requested review of this revision.

This attribute applies to a using declaration, and permits importing a declaration without knowing if that declaration exists. This is useful for libc++ c wrapper headers that re-export declarations in `std::`.

As far as implementation goes, when some declarations are found, this attribute has no effect. When no declaration is found, Sema creates a single `UsingShadowDecl` that targets an `UnresolvedUsingIfExistsDecl`. If the `UnresolvedUsingIfExistsDecl` is referred to later, then an error is emitted. If the using-declaration is dependent, then Sema creates an UnresolvedUsingValueDecl/UnresolvedUsingTypenameDecl (as usual), but on instantiation they generate a `UsingDecl` that refers to an `UnresolvedUsingIfExistsDecl`.

This was proposed by Louis Dionne here: http://lists.llvm.org/pipermail/cfe-dev/2020-June/066038.html
rdar://69313357

Thanks for taking a look!


https://reviews.llvm.org/D90188

Files:
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DeclNodes.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/AST/DeclBase.cpp
  clang/lib/AST/DeclCXX.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprMember.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/SemaCXX/using-if-exists-attr.cpp
  clang/test/SemaCXX/using-if-exists.cpp
  clang/tools/libclang/CIndex.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90188.300716.patch
Type: text/x-patch
Size: 34624 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201026/9cf124f1/attachment-0001.bin>


More information about the cfe-commits mailing list