Ownership.h revision 226633
1283425Sdchagin//===--- Ownership.h - Parser ownership helpers -----------------*- C++ -*-===// 2283425Sdchagin// 3283425Sdchagin// The LLVM Compiler Infrastructure 4283425Sdchagin// 5283425Sdchagin// This file is distributed under the University of Illinois Open Source 6314107Sdchagin// License. See LICENSE.TXT for details. 7283425Sdchagin// 8283425Sdchagin//===----------------------------------------------------------------------===// 9283425Sdchagin// 10283425Sdchagin// This file contains classes for managing ownership of Stmt and Expr nodes. 11283425Sdchagin// 12283425Sdchagin//===----------------------------------------------------------------------===// 13283425Sdchagin 14283425Sdchagin#ifndef LLVM_CLANG_SEMA_OWNERSHIP_H 15283425Sdchagin#define LLVM_CLANG_SEMA_OWNERSHIP_H 16283425Sdchagin 17283425Sdchagin#include "clang/Basic/LLVM.h" 18283425Sdchagin#include "llvm/ADT/SmallVector.h" 19283425Sdchagin#include "llvm/ADT/PointerIntPair.h" 20283425Sdchagin 21283425Sdchagin//===----------------------------------------------------------------------===// 22283425Sdchagin// OpaquePtr 23283425Sdchagin//===----------------------------------------------------------------------===// 24283425Sdchagin 25283425Sdchaginnamespace clang { 26283425Sdchagin class Attr; 27283425Sdchagin class CXXCtorInitializer; 28283425Sdchagin class CXXBaseSpecifier; 29283425Sdchagin class Decl; 30283425Sdchagin class DeclGroupRef; 31283425Sdchagin class Expr; 32283425Sdchagin class NestedNameSpecifier; 33283425Sdchagin class QualType; 34283425Sdchagin class Sema; 35283425Sdchagin class Stmt; 36283425Sdchagin class TemplateName; 37283425Sdchagin class TemplateParameterList; 38283425Sdchagin 39283425Sdchagin /// OpaquePtr - This is a very simple POD type that wraps a pointer that the 40283425Sdchagin /// Parser doesn't know about but that Sema or another client does. The UID 41283425Sdchagin /// template argument is used to make sure that "Decl" pointers are not 42283425Sdchagin /// compatible with "Type" pointers for example. 43283425Sdchagin template <class PtrTy> 44283425Sdchagin class OpaquePtr { 45283425Sdchagin void *Ptr; 46283425Sdchagin explicit OpaquePtr(void *Ptr) : Ptr(Ptr) {} 47283425Sdchagin 48283425Sdchagin typedef llvm::PointerLikeTypeTraits<PtrTy> Traits; 49283425Sdchagin 50283425Sdchagin public: 51283425Sdchagin OpaquePtr() : Ptr(0) {} 52283425Sdchagin 53283425Sdchagin static OpaquePtr make(PtrTy P) { OpaquePtr OP; OP.set(P); return OP; } 54283425Sdchagin 55283425Sdchagin template <typename T> T* getAs() const { 56283425Sdchagin return get(); 57283425Sdchagin } 58283425Sdchagin 59283425Sdchagin template <typename T> T getAsVal() const { 60283425Sdchagin return get(); 61283425Sdchagin } 62283425Sdchagin 63283425Sdchagin PtrTy get() const { 64283425Sdchagin return Traits::getFromVoidPointer(Ptr); 65283425Sdchagin } 66283425Sdchagin 67283425Sdchagin void set(PtrTy P) { 68283425Sdchagin Ptr = Traits::getAsVoidPointer(P); 69283425Sdchagin } 70283425Sdchagin 71283425Sdchagin operator bool() const { return Ptr != 0; } 72283425Sdchagin 73283425Sdchagin void *getAsOpaquePtr() const { return Ptr; } 74283425Sdchagin static OpaquePtr getFromOpaquePtr(void *P) { return OpaquePtr(P); } 75283425Sdchagin }; 76283425Sdchagin 77283425Sdchagin /// UnionOpaquePtr - A version of OpaquePtr suitable for membership 78283425Sdchagin /// in a union. 79283425Sdchagin template <class T> struct UnionOpaquePtr { 80283425Sdchagin void *Ptr; 81283425Sdchagin 82283425Sdchagin static UnionOpaquePtr make(OpaquePtr<T> P) { 83283425Sdchagin UnionOpaquePtr OP = { P.getAsOpaquePtr() }; 84283425Sdchagin return OP; 85283425Sdchagin } 86283425Sdchagin 87283425Sdchagin OpaquePtr<T> get() const { return OpaquePtr<T>::getFromOpaquePtr(Ptr); } 88283425Sdchagin operator OpaquePtr<T>() const { return get(); } 89283425Sdchagin 90283425Sdchagin UnionOpaquePtr &operator=(OpaquePtr<T> P) { 91283425Sdchagin Ptr = P.getAsOpaquePtr(); 92283425Sdchagin return *this; 93283425Sdchagin } 94283425Sdchagin }; 95283425Sdchagin} 96283425Sdchagin 97283425Sdchaginnamespace llvm { 98283425Sdchagin template <class T> 99283425Sdchagin class PointerLikeTypeTraits<clang::OpaquePtr<T> > { 100283425Sdchagin public: 101283425Sdchagin static inline void *getAsVoidPointer(clang::OpaquePtr<T> P) { 102283425Sdchagin // FIXME: Doesn't work? return P.getAs< void >(); 103283425Sdchagin return P.getAsOpaquePtr(); 104283425Sdchagin } 105283425Sdchagin static inline clang::OpaquePtr<T> getFromVoidPointer(void *P) { 106283425Sdchagin return clang::OpaquePtr<T>::getFromOpaquePtr(P); 107283425Sdchagin } 108283425Sdchagin enum { NumLowBitsAvailable = 0 }; 109283425Sdchagin }; 110283425Sdchagin 111283425Sdchagin template <class T> 112283425Sdchagin struct isPodLike<clang::OpaquePtr<T> > { static const bool value = true; }; 113283425Sdchagin} 114283425Sdchagin 115283425Sdchagin 116283425Sdchagin 117283425Sdchagin// -------------------------- About Move Emulation -------------------------- // 118283425Sdchagin// The smart pointer classes in this file attempt to emulate move semantics 119283425Sdchagin// as they appear in C++0x with rvalue references. Since C++03 doesn't have 120283425Sdchagin// rvalue references, some tricks are needed to get similar results. 121283425Sdchagin// Move semantics in C++0x have the following properties: 122283425Sdchagin// 1) "Moving" means transferring the value of an object to another object, 123283425Sdchagin// similar to copying, but without caring what happens to the old object. 124283425Sdchagin// In particular, this means that the new object can steal the old object's 125283425Sdchagin// resources instead of creating a copy. 126283425Sdchagin// 2) Since moving can modify the source object, it must either be explicitly 127283425Sdchagin// requested by the user, or the modifications must be unnoticeable. 128283425Sdchagin// 3) As such, C++0x moving is only allowed in three contexts: 129283425Sdchagin// * By explicitly using std::move() to request it. 130283425Sdchagin// * From a temporary object, since that object cannot be accessed 131283425Sdchagin// afterwards anyway, thus making the state unobservable. 132283425Sdchagin// * On function return, since the object is not observable afterwards. 133283425Sdchagin// 134283425Sdchagin// To sum up: moving from a named object should only be possible with an 135283425Sdchagin// explicit std::move(), or on function return. Moving from a temporary should 136283425Sdchagin// be implicitly done. Moving from a const object is forbidden. 137283425Sdchagin// 138283425Sdchagin// The emulation is not perfect, and has the following shortcomings: 139283425Sdchagin// * move() is not in namespace std. 140283425Sdchagin// * move() is required on function return. 141283425Sdchagin// * There are difficulties with implicit conversions. 142283425Sdchagin// * Microsoft's compiler must be given the /Za switch to successfully compile. 143283425Sdchagin// 144283425Sdchagin// -------------------------- Implementation -------------------------------- // 145283425Sdchagin// The move emulation relies on the peculiar reference binding semantics of 146283425Sdchagin// C++03: as a rule, a non-const reference may not bind to a temporary object, 147283425Sdchagin// except for the implicit object parameter in a member function call, which 148283425Sdchagin// can refer to a temporary even when not being const. 149283425Sdchagin// The moveable object has five important functions to facilitate moving: 150283425Sdchagin// * A private, unimplemented constructor taking a non-const reference to its 151283425Sdchagin// own class. This constructor serves a two-fold purpose. 152283425Sdchagin// - It prevents the creation of a copy constructor that takes a const 153283425Sdchagin// reference. Temporaries would be able to bind to the argument of such a 154283425Sdchagin// constructor, and that would be bad. 155283425Sdchagin// - Named objects will bind to the non-const reference, but since it's 156283425Sdchagin// private, this will fail to compile. This prevents implicit moving from 157283425Sdchagin// named objects. 158283425Sdchagin// There's also a copy assignment operator for the same purpose. 159283425Sdchagin// * An implicit, non-const conversion operator to a special mover type. This 160283425Sdchagin// type represents the rvalue reference of C++0x. Being a non-const member, 161283425Sdchagin// its implicit this parameter can bind to temporaries. 162283425Sdchagin// * A constructor that takes an object of this mover type. This constructor 163283425Sdchagin// performs the actual move operation. There is an equivalent assignment 164283425Sdchagin// operator. 165283425Sdchagin// There is also a free move() function that takes a non-const reference to 166283425Sdchagin// an object and returns a temporary. Internally, this function uses explicit 167283425Sdchagin// constructor calls to move the value from the referenced object to the return 168283425Sdchagin// value. 169283425Sdchagin// 170283425Sdchagin// There are now three possible scenarios of use. 171283425Sdchagin// * Copying from a const object. Constructor overload resolution will find the 172283425Sdchagin// non-const copy constructor, and the move constructor. The first is not 173283425Sdchagin// viable because the const object cannot be bound to the non-const reference. 174283425Sdchagin// The second fails because the conversion to the mover object is non-const. 175283425Sdchagin// Moving from a const object fails as intended. 176283425Sdchagin// * Copying from a named object. Constructor overload resolution will select 177283425Sdchagin// the non-const copy constructor, but fail as intended, because this 178283425Sdchagin// constructor is private. 179283425Sdchagin// * Copying from a temporary. Constructor overload resolution cannot select 180283425Sdchagin// the non-const copy constructor, because the temporary cannot be bound to 181283425Sdchagin// the non-const reference. It thus selects the move constructor. The 182283425Sdchagin// temporary can be bound to the implicit this parameter of the conversion 183283425Sdchagin// operator, because of the special binding rule. Construction succeeds. 184283425Sdchagin// Note that the Microsoft compiler, as an extension, allows binding 185283425Sdchagin// temporaries against non-const references. The compiler thus selects the 186283425Sdchagin// non-const copy constructor and fails, because the constructor is private. 187283425Sdchagin// Passing /Za (disable extensions) disables this behaviour. 188283425Sdchagin// The free move() function is used to move from a named object. 189283425Sdchagin// 190283425Sdchagin// Note that when passing an object of a different type (the classes below 191283425Sdchagin// have OwningResult and OwningPtr, which should be mixable), you get a problem. 192283425Sdchagin// Argument passing and function return use copy initialization rules. The 193283425Sdchagin// effect of this is that, when the source object is not already of the target 194283425Sdchagin// type, the compiler will first seek a way to convert the source object to the 195283425Sdchagin// target type, and only then attempt to copy the resulting object. This means 196283425Sdchagin// that when passing an OwningResult where an OwningPtr is expected, the 197283425Sdchagin// compiler will first seek a conversion from OwningResult to OwningPtr, then 198283425Sdchagin// copy the OwningPtr. The resulting conversion sequence is: 199283425Sdchagin// OwningResult object -> ResultMover -> OwningResult argument to 200283425Sdchagin// OwningPtr(OwningResult) -> OwningPtr -> PtrMover -> final OwningPtr 201283425Sdchagin// This conversion sequence is too complex to be allowed. Thus the special 202283425Sdchagin// move_* functions, which help the compiler out with some explicit 203283425Sdchagin// conversions. 204283425Sdchagin 205283425Sdchaginnamespace clang { 206283425Sdchagin // Basic 207283425Sdchagin class DiagnosticBuilder; 208283425Sdchagin 209283425Sdchagin // Determines whether the low bit of the result pointer for the 210283425Sdchagin // given UID is always zero. If so, ActionResult will use that bit 211283425Sdchagin // for it's "invalid" flag. 212283425Sdchagin template<class Ptr> 213283425Sdchagin struct IsResultPtrLowBitFree { 214283425Sdchagin static const bool value = false; 215283425Sdchagin }; 216283425Sdchagin 217283425Sdchagin /// ActionResult - This structure is used while parsing/acting on 218283425Sdchagin /// expressions, stmts, etc. It encapsulates both the object returned by 219283425Sdchagin /// the action, plus a sense of whether or not it is valid. 220283425Sdchagin /// When CompressInvalid is true, the "invalid" flag will be 221283425Sdchagin /// stored in the low bit of the Val pointer. 222283425Sdchagin template<class PtrTy, 223283425Sdchagin bool CompressInvalid = IsResultPtrLowBitFree<PtrTy>::value> 224283425Sdchagin class ActionResult { 225283425Sdchagin PtrTy Val; 226283425Sdchagin bool Invalid; 227283425Sdchagin 228283425Sdchagin public: 229283425Sdchagin ActionResult(bool Invalid = false) 230314107Sdchagin : Val(PtrTy()), Invalid(Invalid) {} 231283425Sdchagin ActionResult(PtrTy val) : Val(val), Invalid(false) {} 232283425Sdchagin ActionResult(const DiagnosticBuilder &) : Val(PtrTy()), Invalid(true) {} 233283425Sdchagin 234283442Sdchagin // These two overloads prevent void* -> bool conversions. 235283425Sdchagin ActionResult(const void *); 236283425Sdchagin ActionResult(volatile void *); 237283425Sdchagin 238283425Sdchagin bool isInvalid() const { return Invalid; } 239283425Sdchagin bool isUsable() const { return !Invalid && Val; } 240283425Sdchagin 241283425Sdchagin PtrTy get() const { return Val; } 242283425Sdchagin PtrTy release() const { return Val; } 243283425Sdchagin PtrTy take() const { return Val; } 244283425Sdchagin template <typename T> T *takeAs() { return static_cast<T*>(get()); } 245283425Sdchagin 246283425Sdchagin void set(PtrTy V) { Val = V; } 247283425Sdchagin 248283425Sdchagin const ActionResult &operator=(PtrTy RHS) { 249283425Sdchagin Val = RHS; 250283425Sdchagin Invalid = false; 251283425Sdchagin return *this; 252283425Sdchagin } 253283442Sdchagin }; 254283442Sdchagin 255283425Sdchagin // This ActionResult partial specialization places the "invalid" 256283425Sdchagin // flag into the low bit of the pointer. 257283425Sdchagin template<typename PtrTy> 258283425Sdchagin class ActionResult<PtrTy, true> { 259283425Sdchagin // A pointer whose low bit is 1 if this result is invalid, 0 260283425Sdchagin // otherwise. 261283425Sdchagin uintptr_t PtrWithInvalid; 262283425Sdchagin typedef llvm::PointerLikeTypeTraits<PtrTy> PtrTraits; 263283425Sdchagin public: 264283425Sdchagin ActionResult(bool Invalid = false) 265283425Sdchagin : PtrWithInvalid(static_cast<uintptr_t>(Invalid)) { } 266283425Sdchagin 267283425Sdchagin ActionResult(PtrTy V) { 268283425Sdchagin void *VP = PtrTraits::getAsVoidPointer(V); 269283425Sdchagin PtrWithInvalid = reinterpret_cast<uintptr_t>(VP); 270283425Sdchagin assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer"); 271283425Sdchagin } 272283425Sdchagin ActionResult(const DiagnosticBuilder &) : PtrWithInvalid(0x01) { } 273283425Sdchagin 274283425Sdchagin // These two overloads prevent void* -> bool conversions. 275283425Sdchagin ActionResult(const void *); 276283425Sdchagin ActionResult(volatile void *); 277283425Sdchagin 278283425Sdchagin bool isInvalid() const { return PtrWithInvalid & 0x01; } 279283425Sdchagin bool isUsable() const { return PtrWithInvalid > 0x01; } 280283425Sdchagin 281283425Sdchagin PtrTy get() const { 282283425Sdchagin void *VP = reinterpret_cast<void *>(PtrWithInvalid & ~0x01); 283283425Sdchagin return PtrTraits::getFromVoidPointer(VP); 284283425Sdchagin } 285283425Sdchagin PtrTy take() const { return get(); } 286283425Sdchagin PtrTy release() const { return get(); } 287283425Sdchagin template <typename T> T *takeAs() { return static_cast<T*>(get()); } 288283425Sdchagin 289283425Sdchagin void set(PtrTy V) { 290283425Sdchagin void *VP = PtrTraits::getAsVoidPointer(V); 291283425Sdchagin PtrWithInvalid = reinterpret_cast<uintptr_t>(VP); 292283452Sdchagin assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer"); 293283425Sdchagin } 294283425Sdchagin 295283425Sdchagin const ActionResult &operator=(PtrTy RHS) { 296283425Sdchagin void *VP = PtrTraits::getAsVoidPointer(RHS); 297283425Sdchagin PtrWithInvalid = reinterpret_cast<uintptr_t>(VP); 298283425Sdchagin assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer"); 299283425Sdchagin return *this; 300283425Sdchagin } 301283482Sdchagin }; 302283442Sdchagin 303283425Sdchagin /// ASTMultiPtr - A moveable smart pointer to multiple AST nodes. Only owns 304314107Sdchagin /// the individual pointers, not the array holding them. 305283445Sdchagin template <typename PtrTy> class ASTMultiPtr; 306283466Sdchagin 307283425Sdchagin template <class PtrTy> 308283425Sdchagin class ASTMultiPtr { 309283425Sdchagin PtrTy *Nodes; 310283425Sdchagin unsigned Count; 311283445Sdchagin 312283442Sdchagin public: 313283425Sdchagin // Normal copying implicitly defined 314283425Sdchagin ASTMultiPtr() : Nodes(0), Count(0) {} 315314107Sdchagin explicit ASTMultiPtr(Sema &) : Nodes(0), Count(0) {} 316314107Sdchagin ASTMultiPtr(Sema &, PtrTy *nodes, unsigned count) 317314107Sdchagin : Nodes(nodes), Count(count) {} 318314107Sdchagin // Fake mover in Parse/AstGuard.h needs this: 319283425Sdchagin ASTMultiPtr(PtrTy *nodes, unsigned count) : Nodes(nodes), Count(count) {} 320283489Sdchagin 321283425Sdchagin /// Access to the raw pointers. 322283425Sdchagin PtrTy *get() const { return Nodes; } 323283425Sdchagin 324283425Sdchagin /// Access to the count. 325283425Sdchagin unsigned size() const { return Count; } 326283425Sdchagin 327283493Sdchagin PtrTy *release() { 328283489Sdchagin return Nodes; 329314107Sdchagin } 330314107Sdchagin }; 331314107Sdchagin 332314107Sdchagin class ParsedTemplateArgument; 333314107Sdchagin 334314107Sdchagin class ASTTemplateArgsPtr { 335314107Sdchagin ParsedTemplateArgument *Args; 336314107Sdchagin mutable unsigned Count; 337314107Sdchagin 338314107Sdchagin public: 339314107Sdchagin ASTTemplateArgsPtr(Sema &actions, ParsedTemplateArgument *args, 340314107Sdchagin unsigned count) : 341314107Sdchagin Args(args), Count(count) { } 342314107Sdchagin 343314107Sdchagin // FIXME: Lame, not-fully-type-safe emulation of 'move semantics'. 344314107Sdchagin ASTTemplateArgsPtr(ASTTemplateArgsPtr &Other) : 345314107Sdchagin Args(Other.Args), Count(Other.Count) { 346314107Sdchagin } 347314107Sdchagin 348314107Sdchagin // FIXME: Lame, not-fully-type-safe emulation of 'move semantics'. 349314107Sdchagin ASTTemplateArgsPtr& operator=(ASTTemplateArgsPtr &Other) { 350314107Sdchagin Args = Other.Args; 351314107Sdchagin Count = Other.Count; 352314107Sdchagin return *this; 353314107Sdchagin } 354283425Sdchagin 355 ParsedTemplateArgument *getArgs() const { return Args; } 356 unsigned size() const { return Count; } 357 358 void reset(ParsedTemplateArgument *args, unsigned count) { 359 Args = args; 360 Count = count; 361 } 362 363 const ParsedTemplateArgument &operator[](unsigned Arg) const; 364 365 ParsedTemplateArgument *release() const { 366 return Args; 367 } 368 }; 369 370 /// \brief A small vector that owns a set of AST nodes. 371 template <class PtrTy, unsigned N = 8> 372 class ASTOwningVector : public SmallVector<PtrTy, N> { 373 ASTOwningVector(ASTOwningVector &); // do not implement 374 ASTOwningVector &operator=(ASTOwningVector &); // do not implement 375 376 public: 377 explicit ASTOwningVector(Sema &Actions) 378 { } 379 380 PtrTy *take() { 381 return &this->front(); 382 } 383 384 template<typename T> T **takeAs() { return reinterpret_cast<T**>(take()); } 385 }; 386 387 /// An opaque type for threading parsed type information through the 388 /// parser. 389 typedef OpaquePtr<QualType> ParsedType; 390 typedef UnionOpaquePtr<QualType> UnionParsedType; 391 392 /// A SmallVector of statements, with stack size 32 (as that is the only one 393 /// used.) 394 typedef ASTOwningVector<Stmt*, 32> StmtVector; 395 /// A SmallVector of expressions, with stack size 12 (the maximum used.) 396 typedef ASTOwningVector<Expr*, 12> ExprVector; 397 /// A SmallVector of types. 398 typedef ASTOwningVector<ParsedType, 12> TypeVector; 399 400 template <class T, unsigned N> inline 401 ASTMultiPtr<T> move_arg(ASTOwningVector<T, N> &vec) { 402 return ASTMultiPtr<T>(vec.take(), vec.size()); 403 } 404 405 // These versions are hopefully no-ops. 406 template <class T, bool C> 407 inline ActionResult<T,C> move(ActionResult<T,C> &ptr) { 408 return ptr; 409 } 410 411 template <class T> inline 412 ASTMultiPtr<T>& move(ASTMultiPtr<T> &ptr) { 413 return ptr; 414 } 415 416 // We can re-use the low bit of expression, statement, base, and 417 // member-initializer pointers for the "invalid" flag of 418 // ActionResult. 419 template<> struct IsResultPtrLowBitFree<Expr*> { 420 static const bool value = true; 421 }; 422 template<> struct IsResultPtrLowBitFree<Stmt*> { 423 static const bool value = true; 424 }; 425 template<> struct IsResultPtrLowBitFree<CXXBaseSpecifier*> { 426 static const bool value = true; 427 }; 428 template<> struct IsResultPtrLowBitFree<CXXCtorInitializer*> { 429 static const bool value = true; 430 }; 431 432 typedef ActionResult<Expr*> ExprResult; 433 typedef ActionResult<Stmt*> StmtResult; 434 typedef ActionResult<ParsedType> TypeResult; 435 typedef ActionResult<CXXBaseSpecifier*> BaseResult; 436 typedef ActionResult<CXXCtorInitializer*> MemInitResult; 437 438 typedef ActionResult<Decl*> DeclResult; 439 typedef OpaquePtr<TemplateName> ParsedTemplateTy; 440 441 inline Expr *move(Expr *E) { return E; } 442 inline Stmt *move(Stmt *S) { return S; } 443 444 typedef ASTMultiPtr<Expr*> MultiExprArg; 445 typedef ASTMultiPtr<Stmt*> MultiStmtArg; 446 typedef ASTMultiPtr<ParsedType> MultiTypeArg; 447 typedef ASTMultiPtr<TemplateParameterList*> MultiTemplateParamsArg; 448 449 inline ExprResult ExprError() { return ExprResult(true); } 450 inline StmtResult StmtError() { return StmtResult(true); } 451 452 inline ExprResult ExprError(const DiagnosticBuilder&) { return ExprError(); } 453 inline StmtResult StmtError(const DiagnosticBuilder&) { return StmtError(); } 454 455 inline ExprResult ExprEmpty() { return ExprResult(false); } 456 inline StmtResult StmtEmpty() { return StmtResult(false); } 457 458 inline Expr *AssertSuccess(ExprResult R) { 459 assert(!R.isInvalid() && "operation was asserted to never fail!"); 460 return R.get(); 461 } 462 463 inline Stmt *AssertSuccess(StmtResult R) { 464 assert(!R.isInvalid() && "operation was asserted to never fail!"); 465 return R.get(); 466 } 467} 468 469#endif 470