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

    • Type: Bug
    • Status: Reported
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: 5.15.3, 5.15.4
    • Fix Version/s: None
    • Component/s: Core: Other, GUI: Painting
    • Labels:
      None
    • Environment:
      Qt binaries pre-compiled for MSVC 2019 32-bit; Visual Studio 2019 16.9.5; msvc compiler version 19.28.29915 for x86;
    • Platform/s:
      Windows

      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

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

            Activity

              People

              Assignee:
              kkohne Kai Köhne
              Reporter:
              jneuhaus John Neuhaus
              Votes:
              4 Vote for this issue
              Watchers:
              8 Start watching this issue

                Dates

                Created:
                Updated:

                  Gerrit Reviews

                  There are no open Gerrit changes