Commit 9b3969d0 authored by Philipp A. Hartmann's avatar Philipp A. Hartmann

GenericValue: fixup bool constructor

With the new string handling API, the constructor taking a `bool`
parameter matches in some unwanted cases, as pointers can be casted
to `bool` implicitly.

Add a SFINAE helper to this constructor to avoid matching arbitrary
pointers.  To avoid confusion for the user, this mechanism is hidden
from the Doxygen documentation.
parent ed9cdbc2
......@@ -1991,6 +1991,7 @@ INCLUDE_FILE_PATTERNS =
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
PREDEFINED = \
RAPIDJSON_DOXYGEN_RUNNING \
RAPIDJSON_DISABLEIF_RETURN(cond,returntype)=returntype
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
......
......@@ -355,8 +355,6 @@ public:
private:
//! Copy constructor is not permitted.
GenericValue(const GenericValue& rhs);
//! Disabled constructor for arbitrary pointers.
template<typename T> explicit GenericValue(T*);
public:
......@@ -385,7 +383,18 @@ public:
GenericValue(const GenericValue<Encoding,SourceAllocator>& rhs, Allocator & allocator);
//! Constructor for boolean value.
explicit GenericValue(bool b) : data_(), flags_(b ? kTrueFlag : kFalseFlag) {}
/*! \param b Boolean value
\note This constructor is limited to \em real boolean values and rejects
implicitly converted types like arbitrary pointers. Use an explicit cast
to \c bool, if you want to construct a boolean JSON value in such cases.
*/
#ifndef RAPIDJSON_DOXYGEN_RUNNING // hide SFINAE from Doxygen
template <typename T>
explicit GenericValue(T b, RAPIDJSON_ENABLEIF((internal::IsSame<T,bool>)))
#else
explicit GenericValue(bool b)
#endif
: data_(), flags_(b ? kTrueFlag : kFalseFlag) {}
//! Constructor for int value.
explicit GenericValue(int i) : data_(), flags_(kNumberIntFlag) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment