diff options
Diffstat (limited to 'include/clang/AST/LambdaCapture.h')
-rw-r--r-- | include/clang/AST/LambdaCapture.h | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/include/clang/AST/LambdaCapture.h b/include/clang/AST/LambdaCapture.h index ddefa88a6b69..6517d656878e 100644 --- a/include/clang/AST/LambdaCapture.h +++ b/include/clang/AST/LambdaCapture.h @@ -33,10 +33,22 @@ class LambdaCapture { /// given capture was by-copy. /// /// This includes the case of a non-reference init-capture. - Capture_ByCopy = 0x02 + Capture_ByCopy = 0x02, + + /// \brief Flag used by the Capture class to distinguish between a capture + /// of '*this' and a capture of a VLA type. + Capture_This = 0x04 }; - llvm::PointerIntPair<Decl *, 2> DeclAndBits; + // Decl could represent: + // - a VarDecl* that represents the variable that was captured or the + // init-capture. + // - or, is a nullptr and Capture_This is set in Bits if this represents a + // capture of '*this' by value or reference. + // - or, is a nullptr and Capture_This is not set in Bits if this represents + // a capture of a VLA type. + llvm::PointerIntPair<Decl*, 3> DeclAndBits; + SourceLocation Loc; SourceLocation EllipsisLoc; @@ -69,8 +81,8 @@ public: /// \brief Determine whether this capture handles the C++ \c this /// pointer. bool capturesThis() const { - return (DeclAndBits.getPointer() == nullptr) && - !(DeclAndBits.getInt() & Capture_ByCopy); + return DeclAndBits.getPointer() == nullptr && + (DeclAndBits.getInt() & Capture_This); } /// \brief Determine whether this capture handles a variable. @@ -81,8 +93,8 @@ public: /// \brief Determine whether this captures a variable length array bound /// expression. bool capturesVLAType() const { - return (DeclAndBits.getPointer() == nullptr) && - (DeclAndBits.getInt() & Capture_ByCopy); + return DeclAndBits.getPointer() == nullptr && + !(DeclAndBits.getInt() & Capture_This); } /// \brief Retrieve the declaration of the local variable being @@ -91,13 +103,15 @@ public: /// This operation is only valid if this capture is a variable capture /// (other than a capture of \c this). VarDecl *getCapturedVar() const { - assert(capturesVariable() && "No variable available for 'this' capture"); - return cast<VarDecl>(DeclAndBits.getPointer()); + assert(capturesVariable() && "No variable available for capture"); + return static_cast<VarDecl *>(DeclAndBits.getPointer()); } /// \brief Determine whether this was an implicit capture (not /// written between the square brackets introducing the lambda). - bool isImplicit() const { return DeclAndBits.getInt() & Capture_Implicit; } + bool isImplicit() const { + return DeclAndBits.getInt() & Capture_Implicit; + } /// \brief Determine whether this was an explicit capture (written /// between the square brackets introducing the lambda). |