Skip to content

Commit 094b799

Browse files
committed
Fix pointer error checking
1 parent b27af19 commit 094b799

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

main.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ class AllData : public serialize::I
166166
ms.write(os, dataSetPtr);
167167
ms.write(os, dataSetValue);
168168
ms.write(os, dataSetInt);
169+
170+
// static_assert; pointers not allowed
171+
//ms.write(os, pdate);
172+
//ms.write(os, pint);
169173
return os;
170174
}
171175

@@ -200,6 +204,10 @@ class AllData : public serialize::I
200204
ms.read(is, dataSetPtr);
201205
ms.read(is, dataSetValue);
202206
ms.read(is, dataSetInt);
207+
208+
// static_assert; pointers not allowed
209+
//ms.read(is, pdate);
210+
//ms.read(is, pint);
203211
return is;
204212
}
205213

@@ -232,6 +240,10 @@ class AllData : public serialize::I
232240
set<Date*> dataSetPtr;
233241
set<Date> dataSetValue;
234242
set<int> dataSetInt;
243+
244+
// Pointer to data not allowed; static_assert triggered
245+
Date* pdate = nullptr;
246+
int* pint = nullptr;
235247
};
236248

237249
// DataV1 is a version 1 data structure

serialize.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,12 @@ class serialize
483483
template<typename T>
484484
std::istream& read(std::istream& is, T &t_, bool readPrependedType = true)
485485
{
486-
static_assert(!(std::is_pointer<T>::value && std::is_arithmetic<typename std::remove_pointer<T>::type>::value),
487-
"T cannot be a pointer to a built-in data type");
486+
static_assert(!is_unsupported_container<T>::value, "Unsupported C++ container type");
487+
488+
static_assert(!(std::is_pointer<T>::value &&
489+
(std::is_arithmetic<typename std::remove_pointer<T>::type>::value ||
490+
std::is_class<typename std::remove_pointer<T>::type>::value)),
491+
"T cannot be a pointer to a built-in or custom data type");
488492

489493
if (check_stop_parse(is))
490494
return is;
@@ -534,8 +538,10 @@ class serialize
534538
{
535539
static_assert(!is_unsupported_container<T>::value, "Unsupported C++ container type");
536540

537-
static_assert(!(std::is_pointer<T>::value && std::is_arithmetic<typename std::remove_pointer<T>::type>::value),
538-
"T cannot be a pointer to a built-in data type");
541+
static_assert(!(std::is_pointer<T>::value &&
542+
(std::is_arithmetic<typename std::remove_pointer<T>::type>::value ||
543+
std::is_class<typename std::remove_pointer<T>::type>::value)),
544+
"T cannot be a pointer to a built-in or custom data type");
539545

540546
// Is T type a built-in data type (e.g. float, int, ...)?
541547
if (std::is_class<T>::value == false)

0 commit comments

Comments
 (0)