[cfe-dev] How to test for std::move (intersection of Apple and Clang)
Richard Smith
metafoo at gmail.com
Sat Aug 1 11:10:30 PDT 2015
On Jul 31, 2015 4:12 PM, "Jeffrey Walton" <noloader at gmail.com> wrote:
>
> I have the following code:
>
> // R-values: MS at VS2010 (16.00); GCC at 4.3; Clang at 2.9; and Intel
11.1.
> // The extra tests on GCC are because Clang and ICC claims to be GCC 4.
> #if (_MSC_VER >= 1600)
> # define MY_CXX11_RVALUES 1
> #elif defined(__clang__)
> # if __has_feature(cxx_rvalue_references)
> # define MY_CXX11_RVALUES 1
> # endif
> #elif (__INTEL_COMPILER >= 1110)
> # define MY_CXX11_RVALUES 1
> #elif (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
> # define MY_CXX11_RVALUES 1
> #endif // R-value compilers
>
> Then guard the rvalue gear in the declaration and implementation:
>
> if MY_CXX11_RVALUES
> MyClass::MyClass(MyClass&& t)
> : m_alloc(std::move(t.m_alloc)), m_size(t.m_size),
m_ptr(std::move(t.m_ptr))
> {
> t.m_alloc = A();
> t.m_alloc = nullptr;
> t.m_size = 0;
> }
> }
> #endif
>
> Results in:
>
> ./myclass.h:276:18: error: no member named 'move' in namespace 'std'
> : m_alloc(std::move(t.m_alloc)), m_size(t.m_size),
m_ptr...
> ~~~~~^
> ./myclass.h:276:65: error: no member named 'move' in namespace 'std'
> ...: m_alloc(std::move(t.m_alloc)), m_size(t.m_size),
> m_ptr(std::move(t.m_p...
>
> And the compiler:
>
> $ c++ -v
> Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
> Target: x86_64-apple-darwin12.6.0
> Thread model: posix
>
> What is the proper way to guard to rvalues and std::move when using
> Clang on Apple?
You need to test the version of the standard library, not of the compiler,
to detect std::move. Or you could implement your own move function; it's
pretty trivial.
_______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150801/d0a3d2b8/attachment.html>
More information about the cfe-dev
mailing list