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

QT_DEPRECATED_X with Q_REQUIRED_RESULT causes warning C5240 in Visual Studio 16.9.5

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 6.0.0
    • 5.15.3, 5.15.4
    • Core: Other, GUI: Painting
    • None
    • Qt binaries pre-compiled for MSVC 2019 32-bit; Visual Studio 2019 16.9.5; msvc compiler version 19.28.29915 for x86;
    • Windows
    • 93dad2bf91d f921b42f34 (qt/qtbase/dev) f921b42f34 (qt/tqtc-qtbase/dev) e2ff48441b (qt/qtbase/6.4) e2ff48441b (qt/tqtc-qtbase/6.4)

    Description

      Visual Studio 16.9.5 fixed a bug that failed to warn on incorrect placement of attributes.  Consequently, usages of QT_DEPRECATED_X together with Q_REQUIRED_RESULT are now producing compiler warnings.  This happens with QColor::light and dark, and QPainterPath::subtractedInverted in my env/codebase, but maybe also others.

      Specifically, the expansion from (for example)

      QT_DEPRECATED_X("Use QColor::lighter() instead")
      Q_REQUIRED_RESULT QColor light(int f = 150) const noexcept;
      

      into

      __declspec(deprecated("Use QColor::lighter() instead"))
      [[nodiscard]] QColor light(int f = 150) const noexcept;
      

      generates

      warning C5240: 'nodiscard': attribute is ignored in this syntactic position
      

       
      VS now supports the correct syntax of

      [[deprecated("Use QColor::lighter() instead")]]
      [[nodiscard]] QColor light(int f = 150) const noexcept;
      

      which looks was already done specifically for enums in msvc (qcompilerdetection.h line 1153)

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-93748
          # Subject Branch Project Status CR V

          Activity

            People

              kkohne Kai Köhne
              jneuhaus John Neuhaus
              Votes:
              3 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes