Fix Clang -Wexpansion-to-defined warning by deprecating QT_SUPPORTS

The C and C++ standards say it's undefined whether the preprocessor
supports macros that expand to defined() will operate as an ifdef.
Clang 3.9 started complaining about that fact.

One solution was to change QT_SUPPORTS to check for zero or one, which
means we need to change the #defines QT_NO_xxx to #define QT_NO_xxx 1.
The C standard says we don't need to #define to 0, as an unknown token
is interpreted as zero. However, that might produce a warning (GCC with
-Wundef), so changing the macro this way is not recommended.

Instead, we deprecate the macro and replace the uses with #ifdef/ndef.

Change-Id: Id75834dab9ed466e94c7ffff1444874d5680b96a
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Thiago Macieira 2016-04-13 12:36:28 -07:00
parent 1c2210b7b1
commit e1d0da6526
19 changed files with 57 additions and 54 deletions

View File

@ -55,6 +55,9 @@
#include <QtCore/qfeatures.h>
#endif
// The QT_SUPPORTS macro is deprecated. Don't use it in new code.
// Instead, use #ifdef/ndef QT_NO_feature.
// ### Qt6: remove macro
#ifdef _MSC_VER
# define QT_SUPPORTS(FEATURE) (!defined QT_NO_##FEATURE)
#else

View File

@ -65,7 +65,7 @@ QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment,
// Don't allocate empty headers
if (!(options & RawData) && !capacity) {
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
if (options & Unsharable)
return const_cast<QArrayData *>(&qt_array_unsharable_empty);
#endif
@ -110,7 +110,7 @@ QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment,
quintptr data = (quintptr(header) + sizeof(QArrayData) + alignment - 1)
& ~(alignment - 1);
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
header->ref.atomic.store(bool(!(options & Unsharable)));
#else
header->ref.atomic.store(1);
@ -132,7 +132,7 @@ void QArrayData::deallocate(QArrayData *data, size_t objectSize,
&& !(alignment & (alignment - 1)));
Q_UNUSED(objectSize) Q_UNUSED(alignment)
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
if (data == &qt_array_unsharable_empty)
return;
#endif

View File

@ -72,7 +72,7 @@ struct Q_CORE_EXPORT QArrayData
enum AllocationOption {
CapacityReserved = 0x1,
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
Unsharable = 0x2,
#endif
RawData = 0x4,
@ -249,7 +249,7 @@ struct QTypedArrayData
return allocate(/* capacity */ 0);
}
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
static QTypedArrayData *unsharableEmpty()
{
Q_STATIC_ASSERT(sizeof(QTypedArrayData) == sizeof(QArrayData));

View File

@ -127,7 +127,7 @@ public:
return (!d->isMutable() || d->ref.isShared());
}
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
void setSharable(bool sharable)
{
if (needsDetach()) {

View File

@ -96,7 +96,7 @@ public:
inline void detach() { if (d->ref.load() != 1) detach_helper(); }
inline bool isDetached() const { return d->ref.load() == 1; }
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
inline void setSharable(bool sharable) { if (!sharable) detach(); d->sharable = sharable; }
#endif

View File

@ -266,7 +266,7 @@ public:
inline void detach() { if (d->ref.isShared()) detach_helper(); }
inline bool isDetached() const { return !d->ref.isShared(); }
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
inline void setSharable(bool sharable) { if (!sharable) detach(); if (d != &QHashData::shared_null) d->sharable = sharable; }
#endif
bool isSharedWith(const QHash &other) const { return d == other.d; }

View File

@ -99,7 +99,7 @@ public:
inline void detach()
{ if (d->ref.isShared()) detach_helper2(this->e); }
inline bool isDetached() const { return !d->ref.isShared(); }
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
inline void setSharable(bool sharable) { if (!sharable) detach(); if (d != &QLinkedListData::shared_null) d->sharable = sharable; }
#endif
inline bool isSharedWith(const QLinkedList<T> &other) const { return d == other.d; }

View File

@ -169,7 +169,7 @@ public:
}
inline bool isDetached() const { return !d->ref.isShared(); }
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
inline void setSharable(bool sharable)
{
if (sharable == d->ref.isSharable())

View File

@ -359,7 +359,7 @@ public:
inline void detach() { if (d->ref.isShared()) detach_helper(); }
inline bool isDetached() const { return !d->ref.isShared(); }
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
inline void setSharable(bool sharable)
{
if (sharable == d->ref.isSharable())

View File

@ -47,7 +47,7 @@ class RefCount
public:
inline bool ref() Q_DECL_NOTHROW {
int count = atomic.load();
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
if (count == 0) // !isSharable
return false;
#endif
@ -58,7 +58,7 @@ public:
inline bool deref() Q_DECL_NOTHROW {
int count = atomic.load();
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
if (count == 0) // !isSharable
return false;
#endif
@ -67,7 +67,7 @@ public:
return atomic.deref();
}
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
bool setSharable(bool sharable) Q_DECL_NOTHROW
{
Q_ASSERT(!isShared());

View File

@ -79,7 +79,7 @@ public:
inline void detach() { q_hash.detach(); }
inline bool isDetached() const { return q_hash.isDetached(); }
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
inline void setSharable(bool sharable) { q_hash.setSharable(sharable); }
#endif

View File

@ -100,7 +100,7 @@ public:
inline void detach();
inline bool isDetached() const { return !d->ref.isShared(); }
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
inline void setSharable(bool sharable)
{
if (sharable == d->ref.isSharable())
@ -376,7 +376,7 @@ template <typename T>
void QVector<T>::detach()
{
if (!isDetached()) {
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
if (!d->alloc)
d = Data::unsharableEmpty();
else
@ -533,7 +533,7 @@ void QVector<T>::reallocData(const int asize, const int aalloc, QArrayData::Allo
x = Data::allocate(aalloc, options);
Q_CHECK_PTR(x);
// aalloc is bigger then 0 so it is not [un]sharedEmpty
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
Q_ASSERT(x->ref.isSharable() || options.testFlag(QArrayData::Unsharable));
#endif
Q_ASSERT(!x->ref.isStatic());
@ -601,7 +601,7 @@ void QVector<T>::reallocData(const int asize, const int aalloc, QArrayData::Allo
Q_ASSERT(d->data());
Q_ASSERT(uint(d->size) <= d->alloc);
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
Q_ASSERT(d != Data::unsharableEmpty());
#endif
Q_ASSERT(aalloc ? d != Data::sharedNull() : d == Data::sharedNull());

View File

@ -93,7 +93,7 @@ public:
bool isStatic() const { return d->ref.isStatic(); }
bool isShared() const { return d->ref.isShared(); }
bool isSharedWith(const SimpleVector &other) const { return d == other.d; }
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
bool isSharable() const { return d->ref.isSharable(); }
void setSharable(bool sharable) { d.setSharable(sharable); }
#endif

View File

@ -44,7 +44,7 @@ struct SharedNullVerifier
{
Q_ASSERT(QArrayData::shared_null[0].ref.isStatic());
Q_ASSERT(QArrayData::shared_null[0].ref.isShared());
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
Q_ASSERT(QArrayData::shared_null[0].ref.isSharable());
#endif
}
@ -101,7 +101,7 @@ void tst_QArrayData::referenceCounting()
QCOMPARE(array.ref.atomic.load(), 1);
QVERIFY(!array.ref.isStatic());
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
QVERIFY(array.ref.isSharable());
#endif
@ -123,7 +123,7 @@ void tst_QArrayData::referenceCounting()
// Now would be a good time to free/release allocated data
}
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
{
// Reference counting initialized to 0 (non-sharable)
QArrayData array = { { Q_BASIC_ATOMIC_INITIALIZER(0) }, 0, 0, 0, 0 };
@ -151,7 +151,7 @@ void tst_QArrayData::referenceCounting()
QCOMPARE(array.ref.atomic.load(), -1);
QVERIFY(array.ref.isStatic());
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
QVERIFY(array.ref.isSharable());
#endif
@ -178,7 +178,7 @@ void tst_QArrayData::sharedNullEmpty()
QCOMPARE(null->ref.atomic.load(), -1);
QCOMPARE(empty->ref.atomic.load(), -1);
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
QVERIFY(null->ref.isSharable());
QVERIFY(empty->ref.isSharable());
#endif
@ -309,7 +309,7 @@ void tst_QArrayData::simpleVector()
QVERIFY(!v7.isShared());
QVERIFY(!v8.isShared());
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
QVERIFY(v1.isSharable());
QVERIFY(v2.isSharable());
QVERIFY(v3.isSharable());
@ -502,7 +502,7 @@ void tst_QArrayData::simpleVector()
for (int i = 0; i < 120; ++i)
QCOMPARE(v1[i], v8[i % 10]);
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
{
v7.setSharable(true);
QVERIFY(v7.isSharable());
@ -672,7 +672,7 @@ void tst_QArrayData::allocate_data()
QArrayData *shared_empty = QArrayData::allocate(0, Q_ALIGNOF(QArrayData), 0);
QVERIFY(shared_empty);
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
QArrayData *unsharable_empty = QArrayData::allocate(0, Q_ALIGNOF(QArrayData), 0, QArrayData::Unsharable);
QVERIFY(unsharable_empty);
#endif
@ -686,7 +686,7 @@ void tst_QArrayData::allocate_data()
} options[] = {
{ "Default", QArrayData::Default, false, true, shared_empty },
{ "Reserved", QArrayData::CapacityReserved, true, true, shared_empty },
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
{ "Reserved | Unsharable",
QArrayData::CapacityReserved | QArrayData::Unsharable, true, false,
unsharable_empty },
@ -736,7 +736,7 @@ void tst_QArrayData::allocate()
else
QCOMPARE(data->alloc, uint(capacity));
QCOMPARE(data->capacityReserved, uint(isCapacityReserved));
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
QFETCH(bool, isSharable);
QCOMPARE(data->ref.isSharable(), isSharable);
#endif
@ -1316,7 +1316,7 @@ static inline bool arrayIsFilledWith(const QArrayDataPointer<int> &array,
void tst_QArrayData::setSharable_data()
{
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
QTest::addColumn<QArrayDataPointer<int> >("array");
QTest::addColumn<size_t>("size");
QTest::addColumn<size_t>("capacity");
@ -1362,7 +1362,7 @@ void tst_QArrayData::setSharable_data()
void tst_QArrayData::setSharable()
{
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
QFETCH(QArrayDataPointer<int>, array);
QFETCH(size_t, size);
QFETCH(size_t, capacity);
@ -1492,7 +1492,7 @@ void fromRawData_impl()
QVERIFY((const T *)raw.constBegin() != array);
}
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
{
// Immutable, unsharable
SimpleVector<T> raw = SimpleVector<T>::fromRawData(array,
@ -1578,7 +1578,7 @@ void tst_QArrayData::literals()
QVERIFY(v.isStatic());
#endif
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
QVERIFY(v.isSharable());
#endif
QCOMPARE((void*)(const char*)(v.constBegin() + v.size()), (void*)(const char*)v.constEnd());
@ -1629,7 +1629,7 @@ void tst_QArrayData::variadicLiterals()
QVERIFY(v.isStatic());
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
QVERIFY(v.isSharable());
#endif
QCOMPARE((const int *)(v.constBegin() + v.size()), (const int *)v.constEnd());

View File

@ -1191,7 +1191,7 @@ void tst_QHash::noNeedlessRehashes()
void tst_QHash::const_shared_null()
{
QHash<int, QString> hash2;
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
QHash<int, QString> hash1;
hash1.setSharable(false);
QVERIFY(hash1.isDetached());

View File

@ -1027,7 +1027,7 @@ template<typename T>
void tst_QLinkedList::constSharedNull() const
{
QLinkedList<T> list2;
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
QLinkedList<T> list1;
list1.setSharable(false);
QVERIFY(list1.isDetached());
@ -1059,7 +1059,7 @@ void tst_QLinkedList::constSharedNullComplex() const
void tst_QLinkedList::setSharableInt() const
{
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
QLinkedList<int> orglist;
orglist << 0 << 1 << 2 << 3 << 4 << 5;
int size = 6;

View File

@ -1892,7 +1892,7 @@ template<typename T>
void tst_QList::constSharedNull() const
{
QList<T> list2;
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
QList<T> list1;
list1.setSharable(false);
QVERIFY(list1.isDetached());
@ -1926,7 +1926,7 @@ void tst_QList::constSharedNullComplex() const
template <class T>
void generateSetSharableData()
{
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
QTest::addColumn<QList<T> >("list");
QTest::addColumn<int>("size");
@ -1938,7 +1938,7 @@ void generateSetSharableData()
template <class T>
void runSetSharableTest()
{
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
QFETCH(QList<T>, list);
QFETCH(int, size);

View File

@ -1012,7 +1012,7 @@ void tst_QMap::qmultimap_specific()
void tst_QMap::const_shared_null()
{
QMap<int, QString> map2;
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
QMap<int, QString> map1;
map1.setSharable(false);
QVERIFY(map1.isDetached());
@ -1109,7 +1109,7 @@ const T &const_(const T &t)
void tst_QMap::setSharable()
{
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
QMap<int, QString> map;
map.insert(1, "um");

View File

@ -431,7 +431,7 @@ void tst_QVector::copyConstructor() const
QVector<T> v2(v1);
QCOMPARE(v1, v2);
}
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
// ### Qt6 remove this section
{
QVector<T> v1;
@ -595,7 +595,7 @@ void tst_QVector::append() const
QVERIFY(v.size() == 3);
QCOMPARE(v.at(v.size() - 1), SimpleValue<T>::at(0));
}
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
// ### Qt6 remove this section
{
QVector<T> v(2);
@ -930,7 +930,7 @@ void tst_QVector::eraseEmpty() const
v.erase(v.begin(), v.end());
QCOMPARE(v.size(), 0);
}
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
// ### Qt6 remove this section
{
QVector<T> v;
@ -969,7 +969,7 @@ void tst_QVector::eraseEmptyReserved() const
v.erase(v.begin(), v.end());
QCOMPARE(v.size(), 0);
}
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
// ### Qt6 remove this section
{
QVector<T> v;
@ -1085,7 +1085,7 @@ void tst_QVector::erase(bool shared) const
if (shared)
QCOMPARE(SimpleValue<T>::vector(12), *svc.copy);
}
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
// ### Qt6 remove this section
{
QVector<T> v = SimpleValue<T>::vector(10);
@ -1172,7 +1172,7 @@ template<typename T> void tst_QVector::eraseReserved() const
v.erase(v.begin() + 1, v.end() - 1);
QCOMPARE(v.size(), 2);
}
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
// ### Qt6 remove this section
{
QVector<T> v(10);
@ -1907,7 +1907,7 @@ void tst_QVector::resizePOD_data() const
QTest::newRow("nonEmpty") << nonEmpty << 10;
QTest::newRow("nonEmptyReserved") << nonEmptyReserved << 10;
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
// ### Qt6 remove this section
QVector<int> nullNotShared;
QVector<int> emptyNotShared(0, 5);
@ -1982,7 +1982,7 @@ void tst_QVector::resizeComplexMovable_data() const
QTest::newRow("nonEmpty") << nonEmpty << 10;
QTest::newRow("nonEmptyReserved") << nonEmptyReserved << 10;
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
// ### Qt6 remove this section
QVector<Movable> nullNotShared;
QVector<Movable> emptyNotShared(0, 'Q');
@ -2061,7 +2061,7 @@ void tst_QVector::resizeComplex_data() const
QTest::newRow("nonEmpty") << nonEmpty << 10;
QTest::newRow("nonEmptyReserved") << nonEmptyReserved << 10;
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
// ### Qt6 remove this section
QVector<Custom> nullNotShared;
QVector<Custom> emptyNotShared(0, '0');
@ -2500,7 +2500,7 @@ void tst_QVector::initializeListCustom()
void tst_QVector::const_shared_null()
{
QVector<int> v2;
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
// ### Qt6 remove this section
QVector<int> v1;
v1.setSharable(false);
@ -2511,7 +2511,7 @@ void tst_QVector::const_shared_null()
QVERIFY(!v2.isDetached());
}
#if QT_SUPPORTS(UNSHARABLE_CONTAINERS)
#if !defined(QT_NO_UNSHARABLE_CONTAINERS)
// ### Qt6 remove this section
template<typename T>
void tst_QVector::setSharable_data() const