fixing GCC and Clang warnings and errors

This commit is contained in:
Mathew Sutcliffe
2014-07-16 22:18:13 +01:00
parent cd82c7f55d
commit db6c6a6331
3 changed files with 21 additions and 7 deletions

View File

@@ -195,6 +195,7 @@ namespace BlackMisc
void checkEnd(const ConditionalIterator &other) // debugging
{
Q_ASSERT(m_end == other.m_end && m_end == other.m_iterator);
Q_UNUSED(other);
}
private:

View File

@@ -75,20 +75,33 @@ namespace BlackMisc
explicit operator bool() const { return m_isValid; }
//! Dereference operator, returns reference to contained value, undefined if there is no value contained.
T &operator *() { Q_ASSERT(m_isValid); return *reinterpret_cast<T *>(m_bytes); }
T &operator *() { return dereference(); }
//! Dereference operator, returns reference to contained value, undefined if there is no value contained.
const T &operator *() const { Q_ASSERT(m_isValid); return *reinterpret_cast<const T *>(m_bytes); }
const T &operator *() const { return dereference(); }
//! Indirection operator, returns pointer to contained value, undefined if there is no value contained.
T *operator ->() { Q_ASSERT(m_isValid); return reinterpret_cast<T *>(m_bytes); }
T *operator ->() { return &dereference(); }
//! Indirection operator, returns pointer to contained value, undefined if there is no value contained.
const T *operator ->() const { Q_ASSERT(m_isValid); return reinterpret_cast<const T *>(m_bytes); }
const T *operator ->() const { return &dereference(); }
private:
bool m_isValid;
#if defined(Q_COMPILER_UNRESTRICTED_UNIONS)
T &dereference() { Q_ASSERT(m_isValid); return m_obj; }
const T &dereference() const { Q_ASSERT(m_isValid); return m_obj; }
union
{
char m_bytes[sizeof(T)];
T m_obj;
};
#else
T &dereference() { Q_ASSERT(m_isValid); return *reinterpret_cast<T *>(m_bytes); }
const T &dereference() const { Q_ASSERT(m_isValid); return *reinterpret_cast<const T *>(m_bytes); }
char m_bytes[sizeof(T)];
#endif
};
/*!

View File

@@ -124,7 +124,7 @@ namespace BlackMisc
//! @}
//! Constructor.
CRange(I begin, I end) : m_begin(begin), m_end(end) { check(begin, end); }
CRange(I begin, I end) : m_begin(begin), m_end(end) { check(&begin, &end); }
//! Begin and end iterators.
//! @{
@@ -170,9 +170,9 @@ namespace BlackMisc
I m_end;
void check(...) {};
template <class I2, class F> void check(Iterators::ConditionalIterator<I2, F> begin, Iterators::ConditionalIterator<I2, F> end)
template <class I2, class F> void check(Iterators::ConditionalIterator<I2, F> *begin, Iterators::ConditionalIterator<I2, F> *end)
{
begin.checkEnd(end);
begin->checkEnd(*end);
}
};