Details
-
Bug
-
Resolution: Fixed
-
P3: Somewhat important
-
6.4.0 Beta1, 6.4.2, 6.5.0 Beta1
-
MSVC 2019 v16.11.16
-
-
3868f2fa5d42c4d97541b7f9e8a3507eef16008a (qtbase/6.4) 8ba8d1346a562347c398bdd0529d34f94f2ac698 (qtbase/dev), 4bfdf6a3d (dev), 30786ef59 (6.4), a70ebbc67 (6.5)
Description
https://codereview.qt-project.org/c/qt/qtbase/+/399817 introduced a constexpr function, QAnyStringView::isAsciiOnlyCharsAtCompileTime(), to detect ASCII/Latin1 encoding.
Unfortunately, this implementation triggers warning C4702 ("unreachable code") if it is enabled in MSVC, thus blocking compilation when warnings are also treated as errors.
Code
# AnyString.pro QT -= gui CONFIG += c++20 SOURCES += main.cpp QMAKE_CXXFLAGS += -we4702
// main.cpp #include <QAnyStringView> #include <QString> int main() { QAnyStringView("hello"); QAnyStringView(u"hello"_qs); }
Output
cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -permissive- -Zc:__cplusplus -Zc:externConstexpr -we4702 -Zi -MDd -std:c++17 -utf-8 -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc /Fddebug\AnyString.vc.pdb -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DQT_QML_DEBUG -DQT_CORE_LIB -I..\AnyString -I. -IC:\Qt\6.4.0\msvc2019_64\include -IC:\Qt\6.4.0\msvc2019_64\include\QtCore -Idebug -IC:\Qt\6.4.0\msvc2019_64\mkspecs\win32-msvc -Fodebug\ @C:\Users\Dev\AppData\Local\Temp\main.obj.9408.15.jom main.cpp C:\Qt\6.4.0\msvc2019_64\include\QtCore\qanystringview.h(68) : error C4702: unreachable code C:\Qt\6.4.0\msvc2019_64\include\QtCore\qanystringview.h(69) : error C4702: unreachable code C:\Qt\6.4.0\msvc2019_64\include\QtCore\qanystringview.h(70) : error C4702: unreachable code C:\Qt\6.4.0\msvc2019_64\include\QtCore\qanystringview.h(73) : error C4702: unreachable code
Update
The fix at https://codereview.qt-project.org/c/qt/qtbase/+/437324 does not work in C++20 mode because __cpp_lib_is_constant_evaluated is defined in this mode.
For Qt 6.4.2 and Qt 6.5.0-beta1, QAnyStringView("hello"); doesn't trigger the warning but QAnyStringView(u"hello"_qs); does.
Attachments
Issue Links
- is duplicated by
-
QTBUG-107583 Unreachable code in QAnyStringView on MSVC
- Closed