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

QCOMPARE(int , enum) produces unexpected result (g++)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.6.0 RC
    • 5.4.0, 5.5.0
    • Testing: qtestlib
    • None
    • Linux, g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2
    •  57ae1b15b61ac6e45ae6a37d943e600fcd47c388 (qtbase/dev, 20.7.2015, 5.6)

    Description

      void EnumcompareTest::testCase1()
      {
          enum { expectedValue = 3 };
      
          int i = 3;
      
          QCOMPARE(i , expectedValue);
      }
      

      produces

      ******** Start testing of EnumcompareTest *********
      Config: Using QtTest library 5.5.1, Qt 5.5.1 (x86_64-little_endian-lp64 shared (dynamic) debug build; by GCC 4.8.2)
      PASS   : EnumcompareTest::initTestCase()
      FAIL!  : EnumcompareTest::testCase1() Compared values are not the same
         Actual   (i)            : 1
         Expected (expectedValue): 3
         Loc: [../enumcompare/tst_enumcomparetest.cpp(21)]
      PASS   : EnumcompareTest::cleanupTestCase()
      Totals: 2 passed, 1 failed, 0 skipped, 0 blacklisted
      ********* Finished testing of EnumcompareTest *********
      

      Debugging shows that the code ends up in qtbase/src/testlib/qtestcase.h:397

       // NokiaX86 and RVCT do not like implicitly comparing bool with int
          inline bool qCompare(bool const &t1, int const &t2,
                          const char *actual, const char *expected, const char *file, int line)
          {
              return qCompare(int(t1), t2, actual, expected, file, line);
          }
      

      Attachments

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

        Activity

          People

            macadder Jason McDonald
            kleint Friedemann Kleint
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes