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

Using Q_FLAG(S) with scoped enums causes moc to generate invalid code

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P1: Critical
    • 5.12.0 Alpha
    • 5.5.0
    • Build tools: moc
    • None

    Description

      If you declare a flag for a scoped enum using Q_FLAG(S) the genereated moc file causes a compiler error.

      example class
      class Foo : public QObject
      {
      	Q_OBJECT
      
      public:
      	enum Bar { BarA };
      	Q_ENUMS(Bar)
      	Q_DECLARE_FLAGS(BarFlag, Bar)
      	Q_FLAGS(BarFlag)
      
      
      	enum class BarClass { A };
      	Q_ENUMS(BarClass)
      	Q_DECLARE_FLAGS(BarClassFlag, BarClass)
      	Q_FLAGS(BarClassFlag)
      };
      
      moc generated code
       // enum data: key, value
             2, uint(Foo::BarA),
             2, uint(Foo::BarA),
             5, uint(Foo::BarClass::A),
             5, uint(Foo::BarClassFlag::A),
      
      compiler error GCC
      moc_foo.cpp:69:16: error: 'A' is not a member of 'Foo::BarClassFlag {aka QFlags<Foo::BarClass>}'
              5, uint(Foo::BarClassFlag::A),
                      ^
      
      compiler error Clang
      moc_foo.cpp:69:35: error: no member named 'A' in 'QFlags<Foo::BarClass>'
             5, uint(Foo::BarClassFlag::A),
                     ~~~~~~~~~~~~~~~~~~~^
      

      Attachments

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

        Activity

          People

            allan.jensen Allan Sandfeld Jensen
            mkrems Marcel Krems
            Votes:
            13 Vote for this issue
            Watchers:
            14 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes