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

[Reg 6.3.1 -> 6.4.0b1] Unavoidable "unreachable code" warnings from qanystringview.h

    XMLWordPrintable

Details

    • Windows
    • 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

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

          Activity

            People

              thiago Thiago Macieira
              skoh-qt Sze Howe Koh
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes