Wrong reinterpretation of the nullptr in a Qt 5.15-based project | C++

117 Views Asked by At

Both GCC (version 12.2) and Clang (version 14.0) compilers interpret nullptr as 32-bit integer (int) in some places, and this causes errors.

For example, in the qhashfunctions.h file there is a variant of function called qHash that takes nullptr as a main argument.

Q_DECL_CONST_FUNCTION inline uint qHash(std::nullptr_t, uint seed = 0) Q_DECL_NOTHROW
{
    return qHash(reinterpret_cast<quintptr>(nullptr), seed);
}

Any compiler reports that int cannot be casted to quintptr (unsigned long long).

Second example has the same problem. In the std_thread.h file there is the following code:

_M_start_thread(_State_ptr(new _State_impl<_Wrapper>(
          std::forward<_Callable>(__f), std::forward<_Args>(__args)...)),
        __depend);
      }

Earlier in this file __depend is declared as nullptr (auto __depend = nullptr;). This means that function pointer (2nd argument) is nullptr. Any compiler reports that a parameter of type void (*)() cannot be initialised with a value of type int.

What is the solution to the problem?

I use ArchLinux (x86-64) with latest updates and Qt version 5.15.8. Building is done through Qt Creator

I also tried to create another Qt-based project and write the following code in the main function:

unsigned long long i = reinterpret_cast<unsigned long long>(nullptr)

Compilation succeded...

0

There are 0 best solutions below