Details
-
Bug
-
Resolution: Duplicate
-
Not Evaluated
-
None
-
6.4.0
-
None
Description
Compilation of QAnyStringView fails on Windows with the compiler option to treat all warnings (except external) as errors due to unreachable code in theĀ isAsciiOnlyCharsAtCompileTime function:
C:\Qt\6.4.0\msvc2019_64\include\QtCore\qanystringview.h(68) : error C2220: the following warning is treated as an error C:\Qt\6.4.0\msvc2019_64\include\QtCore\qanystringview.h(68) : warning C4702: unreachable code
While we identified two possible workarounds, none of the two options is satisfactory:
- Pass /wd4702 as a compilation option; however this would also ignore unreachable code in our own codebase;
- Wrap all code which invokes the constructor of QAnyStringView with pragmas that disable the warning; however this severly pollutes the code.
Minimal example:
main.cpp
#include <QSettings> int main(int /*argc*/, char* /*argv*/[]) { QSettings settings; settings.value("triggers unreachable code"); return 0; }
CMakeLists.txt
cmake_minimum_required(VERSION 3.14) project(minimal-example LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CXX_WARNINGS_AS_ERRORS $<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>) set(CXX_NO_SYSTEM_HEADER_WARNINGS $<$<CXX_COMPILER_ID:MSVC>:/experimental:external /external:anglebrackets /external:W0>) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) add_executable(minimal-example main.cpp) target_link_libraries(minimal-example Qt${QT_VERSION_MAJOR}::Core) target_compile_options(minimal-example PRIVATE ${CXX_NO_SYSTEM_HEADER_WARNINGS} ${CXX_WARNINGS_AS_ERRORS}) install(TARGETS minimal-example LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
Introduces with MSVC 19.29.30146.0
Attachments
Issue Links
- duplicates
-
QTBUG-104836 [Reg 6.3.1 -> 6.4.0b1] Unavoidable "unreachable code" warnings from qanystringview.h
- Closed