Details
-
Bug
-
Resolution: Fixed
-
P3: Somewhat important
-
6.4.2
-
None
-
Qt 6.4.2, MSVC 2022 17.5.2
-
ce58c66ae (dev), a17af86ae (6.5)
Description
If compiling with Visual Studio with warning C4242 enabled (loss of data due to converting to a smaller type - https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4242?view=msvc-170) QTaggedPointer generates warnings due to this code:
static constexpr quint8 tagBits = QtPrivate::qConstexprCountTrailingZeroBits(alignment);
as qConstexprCountTrailingZeroBits is returning int.
This results in the following warnings when using QSequentialIteratable for example:
1>C:\qt\Qt6.4.2\6.4.2\msvc2019_64\include\QtCore/qtaggedpointer.h(24,1): warning C4242: 'initializing': conversion from 'uint' to 'const quint8', possible loss of data 1>C:\qt\Qt6.4.2\6.4.2\msvc2019_64\include\QtCore/qtaggedpointer.h(55,1): message : see reference to class template instantiation 'QtPrivate::TagInfo<T>' being compiled 1> with 1> [ 1> T=quint16 1> ] 1>C:\qt\Qt6.4.2\6.4.2\msvc2019_64\include\QtCore/qtaggedpointer.h(49,1): message : while compiling class template member function 'QTaggedPointer<Storage,QtPrivate::QConstPreservingPointer<void,Storage>::Tag>::QTaggedPointer(T *,Tag) noexcept' 1> with 1> [ 1> Storage=quint16, 1> T=quint16, 1> Tag=QtPrivate::QConstPreservingPointer<void,quint16>::Tag 1> ] 1>C:\qt\Qt6.4.2\6.4.2\msvc2019_64\include\QtCore/qiterable.h(32,24): message : see reference to function template instantiation 'QTaggedPointer<Storage,QtPrivate::QConstPreservingPointer<void,Storage>::Tag>::QTaggedPointer(T *,Tag) noexcept' being compiled 1> with 1> [ 1> Storage=quint16, 1> T=quint16, 1> Tag=QtPrivate::QConstPreservingPointer<void,quint16>::Tag 1> ] 1>C:\qt\Qt6.4.2\6.4.2\msvc2019_64\include\QtCore/qiterable.h(19): message : see reference to class template instantiation 'QTaggedPointer<Storage,QtPrivate::QConstPreservingPointer<void,Storage>::Tag>' being compiled 1> with 1> [ 1> Storage=quint16 1> ] 1>C:\qt\Qt6.4.2\6.4.2\msvc2019_64\include\QtCore/qiterable.h(413): message : see reference to class template instantiation 'QtPrivate::QConstPreservingPointer<void,quint16>' being compiled 1>C:\qt\Qt6.4.2\6.4.2\msvc2019_64\include\QtCore/qiterable.h(508,2): message : see reference to class template instantiation 'QIterable<Container>' being compiled 1>C:\qt\Qt6.4.2\6.4.2\msvc2019_64\include\QtCore/qforeach.h(66,5): warning C4996: 'QtPrivate::warnIfContainerIsNotShared': Do not use foreach/Q_FOREACH with containers which are not implicitly shared. Prefer using a range-based for loop with these containers: `for (const auto &it : container)`, keeping in mind that range-based for doesn't copy the container as Q_FOREACH does 1>test.cc(15,9): message : see reference to function template instantiation 'QtPrivate::QForeachContainer<QSequentialIterable> QtPrivate::qMakeForeachContainer<QSequentialIterable&>(T)' being compiled 1> with 1> [ 1> T=QSequentialIterable & 1> ]
Example program (from the documentation) attached.