[cfe-dev] Using unique_ptr in both C++03 and C++11 mode?

Halfdan Ingvarsson halfdan at sidefx.com
Mon Jul 27 07:48:17 PDT 2015


Try:

clang -mmacosx-version-min=10.9 -std=c++11 -DNDEBUG -g2 -O3 -fPIC 
-march=native -Wall -Wextra -pipe -c 3way.cpp

Otherwise it uses the old gcc 4.2 libstc++ headers, for compatibility 
with OSX 10.8 and below, which don't define std::unique_ptr.

  - ½

On 2015-07-27 10:23 AM, Jeffrey Walton wrote:
> My apologies for asking a user question on CFE Devs... I bring it here
> because the CFE Devs told me to do this a long time ago (cf.,
> http://clang-developers.42468.n3.nabble.com/Suggestion-for-C-migration-tool-tr1-removal-td4030729.html),
> and Marshall Clow stated TR1 is no longer since C++11 (cf.,
> http://marshall.calepin.co/c-and-xcode-46.html).
>
> #if (__cplusplus >= 201103L) // C++11
> # include <memory>
> #elif defined(__APPLE__) // C++03 and Apple
> # 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
> # if defined(__APPLE__)
>    using std::tr1::auto_ptr;
> # else
>    using std::auto_ptr;
> # endif // Apple
> #endif // C++11
>
> The above results in a compile failure:
>
> $ make
> c++ -std=c++11 -DNDEBUG -g2 -O3 -fPIC -march=native -Wall -Wextra
> -pipe -c 3way.cpp
> In file included ...
> ./smartptr.h:27:20: error: unknown type name 'unique_ptr'
>    using auto_ptr = std::unique_ptr<T>;
>                     ^
> ./smartptr.h:27:30: error: expected ';' after alias declaration
>    using auto_ptr = std::unique_ptr<T>;
>
> How do we manage auto_ptr/unique_ptr on Apple platforms under Clang?
> What is the secret sauce I am missing?
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev





More information about the cfe-dev mailing list