Skip to content

Commit 8ceda86

Browse files
committed
Don't return references to temporary values
1 parent 219614b commit 8ceda86

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

hdr/sqlite_modern_cpp.h

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -790,14 +790,10 @@ namespace sqlite {
790790
#ifdef MODERN_SQLITE_STD_OPTIONAL_SUPPORT
791791
template <typename OptionalT> inline database_binder& operator <<(database_binder& db, const std::optional<OptionalT>& val) {
792792
if(val) {
793-
return operator << (std::move(db), std::move(*val));
794-
}
795-
int hresult;
796-
if((hresult = sqlite3_bind_null(db._stmt.get(), db._next_index())) != SQLITE_OK) {
797-
errors::throw_sqlite_error(hresult, db.sql());
793+
return db << std::move(*val);
794+
} else {
795+
return db << nullptr;
798796
}
799-
800-
return db;
801797
}
802798
template <typename OptionalT> inline void store_result_in_db(sqlite3_context* db, const std::optional<OptionalT>& val) {
803799
if(val) {
@@ -830,14 +826,10 @@ namespace sqlite {
830826
#ifdef _MODERN_SQLITE_BOOST_OPTIONAL_SUPPORT
831827
template <typename BoostOptionalT> inline database_binder& operator <<(database_binder& db, const boost::optional<BoostOptionalT>& val) {
832828
if(val) {
833-
return operator << (std::move(db), std::move(*val));
834-
}
835-
int hresult;
836-
if((hresult = sqlite3_bind_null(db._stmt.get(), db._next_index())) != SQLITE_OK) {
837-
errors::throw_sqlite_error(hresult, db.sql());
829+
return db << std::move(*val);
830+
} else {
831+
return db << nullptr;
838832
}
839-
840-
return db;
841833
}
842834
template <typename BoostOptionalT> inline void store_result_in_db(sqlite3_context* db, const boost::optional<BoostOptionalT>& val) {
843835
if(val) {
@@ -892,7 +884,7 @@ namespace sqlite {
892884
void inline operator++(database_binder& db, int) { db.execute(); }
893885

894886
// Convert the rValue binder to a reference and call first op<<, its needed for the call that creates the binder (be carefull of recursion here!)
895-
template<typename T> database_binder& operator << (database_binder&& db, const T& val) { return db << val; }
887+
template<typename T> database_binder&& operator << (database_binder&& db, const T& val) { db << val; return std::move(db); }
896888

897889
namespace sql_function_binder {
898890
template<class T>

0 commit comments

Comments
 (0)