Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-107583

Unreachable code in QAnyStringView on MSVC

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 6.4.0
    • None
    • Windows

    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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              thiago Thiago Macieira
              nielsb Niels Billen
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes