From: David Blaikie Date: Thu, 21 Feb 2013 06:05:57 +0000 (+0000) Subject: Make Optional's operator bool 'explicit' in C++11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=86d88f7168bed7dc6edd92145a91ec2754cd1cf1;p=platform%2Fupstream%2Fllvm.git Make Optional's operator bool 'explicit' in C++11 Provides a general way to add 'explicit' for conversion operators (a no-op when compiling as C++98). llvm-svn: 175723 --- diff --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h index 844e309..c5dc299 100644 --- a/llvm/include/llvm/ADT/Optional.h +++ b/llvm/include/llvm/ADT/Optional.h @@ -86,7 +86,7 @@ public: const T& getValue() const LLVM_LVALUE_FUNCTION { assert(hasVal); return *getPointer(); } T& getValue() LLVM_LVALUE_FUNCTION { assert(hasVal); return *getPointer(); } - operator bool() const { return hasVal; } + LLVM_EXPLICIT operator bool() const { return hasVal; } bool hasValue() const { return hasVal; } const T* operator->() const { return getPointer(); } T* operator->() { return getPointer(); } diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h index adc0ce2..25f42a9 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -341,4 +341,14 @@ # define LLVM_IS_UNALIGNED_ACCESS_FAST 0 #endif +/// \macro LLVM_EXPLICIT +/// \brief Expands to explicit on compilers which support explicit conversion +/// operators. Otherwise expands to nothing. +#if (__has_feature(cxx_explicit_conversions) \ + || defined(__GXX_EXPERIMENTAL_CXX0X__)) +#define LLVM_EXPLICIT explicit +#else +#define LLVM_EXPLICIT +#endif + #endif