[cfe-dev] Using unique_ptr in both C++03 and C++11 mode?
Jeffrey Walton
noloader at gmail.com
Mon Jul 27 07:55:32 PDT 2015
>>>> Why are you trying to special-case __APPLE__ at all? You might want to have different things for libstdc++ / libc++, but that’s not an Apple/everyone else distinction.
>>>
>>> Because Apple fiddles with things. I.e., its broke without the Apple
>>> defines, too.
>>
>> Do you have test cases for this? I’ve not encountered any problems moving C++ code between OS X and FreeBSD, the only time I need portability #defines is when I also want to move it to a platform where libstdc++ is the default C++ standard library implementation.
>>
>
> Well, I'm kind of suffering one as we speak :)
>
> What would you like me to submit?
I think these are the four test cases. Two of them fail...
* c++ -c test-clapple.cxx
* OK
* c++ -stdlib=libc++ -c test-clapple.cxx
* FAIL
* c++ -std=c++11 -c test-clapple.cxx
* FAIL
* c++ -std=c++11 -stdlib=libc++ -c test-clapple.cxx
* OK
*******
$ cat test-clapple.cxx
// Need to test {C++03,C++11} x {libc++, no libc++}
// c++ -c test-clapple.cxx
// c++ -stdlib=libc++ -c test-clapple.cxx
// c++ -std=c++11 -c test-clapple.cxx
// c++ -std=c++11 -stdlib=libc++ -c test-clapple.cxx
// http://marshall.calepin.co/c-and-xcode-46.html
#if (__cplusplus >= 201103L) // C++11
# include <memory>
#elif defined(__clang__) // C++03 and Clang
# include <tr1/memory>
#else // C++03 and everyone else
# include <memory>
#endif
// Manage auto_ptr warnings and deprecation in C++11
#if (__cplusplus >= 201103L)
template<typename T>
using auto_ptr = std::unique_ptr<T>;
#else
using std::auto_ptr;
#endif // C++11
int main(int argc, char* argv[])
{
return argc;
}
More information about the cfe-dev
mailing list