Make Qt headers work with MSVC /W4

This requires explicitly marking constexpr if conditions to fix C4127
issues:

  qtbase/src/corelib/text/qstringbuilder.h(112):
  error C2220: the following warning is treated as an error
  qtbase/src/corelib/text/qstringbuilder.h(112):
  warning C4127: conditional expression is constant
  qtbase/src/corelib/text/qstringbuilder.h(112):
  note: consider using 'if constexpr' statement instead

Change-Id: I9787fb37099f811c52f93c94c9edb4da8aafdfe5
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Kai Köhne 2023-07-11 16:14:07 +02:00
parent 3bb488fb2a
commit 892448b6e0
3 changed files with 29 additions and 20 deletions

View File

@ -186,7 +186,7 @@ function(qt_internal_add_headersclean_target module_target module_headers)
# Note we can't enable -Za, as it does not support certain key Microsoft SDK header files
# we use. Microsoft suggests to use /permissive- instead, which is implicity set by
# -std:c++latest.
set(hcleanFLAGS -std:c++latest -Zc:__cplusplus -WX -W3 -EHsc)
set(hcleanFLAGS -std:c++latest -Zc:__cplusplus -WX -W4 -EHsc)
# Because we now add `-DNOMINMAX` to `PlatformCommonInternal`.
set(hcleanUDEFS -UNOMINMAX)

View File

@ -71,28 +71,32 @@ public:
QTaggedIterator(Iterator &&it) : Iterator(std::move(it))
{
const QMetaContainer metaContainer = this->metaContainer();
if (std::is_base_of_v<std::random_access_iterator_tag, IteratorCategory>
&& !metaContainer.hasRandomAccessIterator()) {
qFatal("You cannot use this iterator as a random access iterator");
this->clearIterator();
if constexpr (std::is_base_of_v<std::random_access_iterator_tag, IteratorCategory>) {
if (!metaContainer.hasRandomAccessIterator()) {
qFatal("You cannot use this iterator as a random access iterator");
this->clearIterator();
}
}
if (std::is_base_of_v<std::bidirectional_iterator_tag, IteratorCategory>
&& !metaContainer.hasBidirectionalIterator()) {
qFatal("You cannot use this iterator as a bidirectional iterator");
this->clearIterator();
if constexpr (std::is_base_of_v<std::bidirectional_iterator_tag, IteratorCategory>) {
if (!metaContainer.hasBidirectionalIterator()) {
qFatal("You cannot use this iterator as a bidirectional iterator");
this->clearIterator();
}
}
if (std::is_base_of_v<std::forward_iterator_tag, IteratorCategory>
&& !metaContainer.hasForwardIterator()) {
qFatal("You cannot use this iterator as a forward iterator");
this->clearIterator();
if constexpr (std::is_base_of_v<std::forward_iterator_tag, IteratorCategory>) {
if (!metaContainer.hasForwardIterator()) {
qFatal("You cannot use this iterator as a forward iterator");
this->clearIterator();
}
}
if (std::is_base_of_v<std::input_iterator_tag, IteratorCategory>
&& !metaContainer.hasInputIterator()) {
qFatal("You cannot use this iterator as an input iterator");
this->clearIterator();
if constexpr (std::is_base_of_v<std::input_iterator_tag, IteratorCategory>) {
if (!metaContainer.hasInputIterator()) {
qFatal("You cannot use this iterator as an input iterator");
this->clearIterator();
}
}
}

View File

@ -106,10 +106,15 @@ private:
// we abuse const_cast / constData here because we know we've just
// allocated the data and we're the only reference count
typename T::iterator d = const_cast<typename T::iterator>(s.constData());
typename T::const_iterator const start = d;
QConcatenable< QStringBuilder<A, B> >::appendTo(*this, d);
if (!QConcatenable< QStringBuilder<A, B> >::ExactSize && len != d - start) {
if constexpr (QConcatenable<QStringBuilder<A, B>>::ExactSize) {
QConcatenable<QStringBuilder<A, B>>::appendTo(*this, d);
return s;
}
typename T::const_iterator const start = d;
QConcatenable<QStringBuilder<A, B>>::appendTo(*this, d);
if (len != d - start) {
// this resize is necessary since we allocate a bit too much
// when dealing with variable sized 8-bit encodings
s.resize(d - start);