2

Recently, by looking at the source code of std::move, I discovered that Qt links my programs with a version of the Standard Library which does not support C++11/14 features:

#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES

template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename remove_reference<_Tp>::type&&
move(_Tp&& __t) _NOEXCEPT
{
    typedef typename remove_reference<_Tp>::type _Up;
    return static_cast<_Up&&>(__t);
}

#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES

template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_Tp&
move(_Tp& __t)
{
    return __t;
}

template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
const _Tp&
move(const _Tp& __t)
{
    return __t;
}

#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES

Actually, the macro _LIBCPP_HAS_NO_RVALUE_REFERENCES is defined (I use CONFIG += C++14 in my .pro file, but this is a problem of the library).

Do I have to rebuild libc++ in order to use C++ features (like proper std::move) with Qt? Or maybe I have to change some settings?

I use Qt 5.7 with LLVM 7.3.0.

Mattia F.
  • 1,720
  • 11
  • 21
  • It isn't supported, take a look [here](http://stackoverflow.com/q/26127217/6614294) –  Aug 26 '16 at 14:35
  • @JamesCalder I can use C++11/14 features, but I'm using a version of libc++ which does not support C++11/14. – Mattia F. Aug 26 '16 at 14:40
  • You wrong. Started from Qt 5.7 compiler should support at least C++11. So they are using it. And they do a lot of refactoring to optimize performance with C++11 features like move ctors or perfect forwarding. – Dmitry Sazonov Aug 26 '16 at 14:44
  • I doubt that it's using C++11 since _LIBCPP_HAS_NO_RVALUE_REFERENCES is defined – Mattia F. Aug 26 '16 at 14:45
  • Which version of qt are you using? – Jason C Aug 26 '16 at 14:46
  • Qt 5.7 with LLVM 7.3.0 – Mattia F. Aug 26 '16 at 14:48
  • 1
    Maybe same problem as this SO question: http://stackoverflow.com/questions/27858273/c14-support-in-qtcreator-with-clang – Julian Aug 26 '16 at 15:08
  • Check where it's defined. It might be a problem with compiler detection. I presume that you've build Qt yourself? What was the `configure` line? You can find it in the build folder in `qtbase/config.status`. – Kuba hasn't forgotten Monica Aug 26 '16 at 16:21
  • It's defined in `type_traits` (as far as I know it should be defined in `utility`). No, I have not build Qt by myself. – Mattia F. Aug 26 '16 at 16:22
  • Qt does not ship with an implementation of the standard library. Any implementation it's trying to link against was already present. Also, Qt 5.7 *requires* at least C++11 (though not 14). – jonspaceharper Aug 26 '16 at 20:53

2 Answers2

1

Qt uses whatever standard library your LLVM is using by default. This problem has nothing to do with Qt, anything you compile with your LLVM will suffer from the same issue. Most likely your LLVM install is borked.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
0

I've seen this tons of times before. You're currently including libstdc++ v4.2 or something. You need to add -stdlib=libc++. Then C++14 will start to work.

EricWF
  • 1,005
  • 7
  • 8