Skip to content

Commit

Permalink
Disable the pointer-bool conversion for value (vesoft-inc#472)
Browse files Browse the repository at this point in the history
* Disable the pointer-bool conversion for value.

* Fix the gcc error.
  • Loading branch information
Shylock-Hg authored Mar 31, 2021
1 parent 0f13a92 commit 6d6c760
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 37 deletions.
80 changes: 43 additions & 37 deletions src/common/datatypes/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,43 +84,49 @@ struct Value {
Value(Value&& rhs) noexcept;
Value(const Value& rhs);

Value(const NullType& v); // NOLINT
Value(NullType&& v); // NOLINT
Value(const bool& v); // NOLINT
Value(bool&& v); // NOLINT
Value(const int8_t& v); // NOLINT
Value(int8_t&& v); // NOLINT
Value(const int16_t& v); // NOLINT
Value(int16_t&& v); // NOLINT
Value(const int32_t& v); // NOLINT
Value(int32_t&& v); // NOLINT
Value(const int64_t& v); // NOLINT
Value(int64_t&& v); // NOLINT
Value(const double& v); // NOLINT
Value(double&& v); // NOLINT
Value(const std::string& v); // NOLINT
Value(std::string&& v); // NOLINT
Value(const char* v); // NOLINT
Value(const Date& v); // NOLINT
Value(Date&& v); // NOLINT
Value(const Time& v); // NOLINT
Value(Time&& v); // NOLINT
Value(const DateTime& v); // NOLINT
Value(DateTime&& v); // NOLINT
Value(const Vertex& v); // NOLINT
Value(Vertex&& v); // NOLINT
Value(const Edge& v); // NOLINT
Value(Edge&& v); // NOLINT
Value(const Path& v); // NOLINT
Value(Path&& v); // NOLINT
Value(const List& v); // NOLINT
Value(List&& v); // NOLINT
Value(const Map& v); // NOLINT
Value(Map&& v); // NOLINT
Value(const Set& v); // NOLINT
Value(Set&& v); // NOLINT
Value(const DataSet& v); // NOLINT
Value(DataSet&& v); // NOLINT
// For the cpp bool-pointer conversion, if Value ctor accept a pointer without matched ctor
// it will convert to bool type and the match the bool value ctor,
// So we disable all pointer ctor except the char*
template <typename T>
Value(T *) = delete; // NOLINT
Value(const std::nullptr_t) = delete; // NOLINT
Value(const NullType& v); // NOLINT
Value(NullType&& v); // NOLINT
Value(const bool& v); // NOLINT
Value(bool&& v); // NOLINT
Value(const int8_t& v); // NOLINT
Value(int8_t&& v); // NOLINT
Value(const int16_t& v); // NOLINT
Value(int16_t&& v); // NOLINT
Value(const int32_t& v); // NOLINT
Value(int32_t&& v); // NOLINT
Value(const int64_t& v); // NOLINT
Value(int64_t&& v); // NOLINT
Value(const double& v); // NOLINT
Value(double&& v); // NOLINT
Value(const std::string& v); // NOLINT
Value(std::string&& v); // NOLINT
Value(const char* v); // NOLINT
Value(const Date& v); // NOLINT
Value(Date&& v); // NOLINT
Value(const Time& v); // NOLINT
Value(Time&& v); // NOLINT
Value(const DateTime& v); // NOLINT
Value(DateTime&& v); // NOLINT
Value(const Vertex& v); // NOLINT
Value(Vertex&& v); // NOLINT
Value(const Edge& v); // NOLINT
Value(Edge&& v); // NOLINT
Value(const Path& v); // NOLINT
Value(Path&& v); // NOLINT
Value(const List& v); // NOLINT
Value(List&& v); // NOLINT
Value(const Map& v); // NOLINT
Value(Map&& v); // NOLINT
Value(const Set& v); // NOLINT
Value(Set&& v); // NOLINT
Value(const DataSet& v); // NOLINT
Value(DataSet&& v); // NOLINT
~Value() { clear(); }

Type type() const noexcept {
Expand Down
26 changes: 26 additions & 0 deletions src/common/datatypes/test/ValueTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,32 @@ TEST(Value, DecodeEncode) {
EXPECT_EQ(val, valCopy);
}
}

TEST(Value, Ctor) {
Value vZero(0);
EXPECT_TRUE(vZero.isInt());
Value vFloat(3.14);
EXPECT_TRUE(vFloat.isFloat());
Value vStr("Hello ");
EXPECT_TRUE(vStr.isStr());
Value vBool(false);
EXPECT_TRUE(vBool.isBool());
Value vDate(Date(2020, 1, 1));
EXPECT_TRUE(vDate.isDate());
Value vList(List({1, 3, 2}));
EXPECT_TRUE(vList.isList());
Value vSet(Set({8, 7}));
EXPECT_TRUE(vSet.isSet());
Value vMap(Map({{"a", 9}, {"b", 10}}));
EXPECT_TRUE(vMap.isMap());

// Disabled
// Lead to compile error
// Value v(nullptr);
// std::map<std::string, std::string> tmp;
// Value v2(&tmp);
}

} // namespace nebula


Expand Down

0 comments on commit 6d6c760

Please sign in to comment.