Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No type named 'nullptr_t' in namespace 'std'

Tags:

macos

gcc

c++11

qt

Someone is compiling my Qt program that is using the C++11 standard and they got this error (Mac OS X / gcc). I know I can declare it, but shouldn't it be already in <cstddef>?

./collectable_smartptr.hpp:54:33: error: no type named 'nullptr_t' in namespace 'std'
void operator=(std::nullptr_t &null)

This code works just fine on Windows and Linux, I see it just on Mac.

Mac is i386-apple-darwin11.3.0, compiler is:

$ g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.2.0
Thread model: posix

g++ options (some) are -c -pipe -std=c++11 -O2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W -DQT_USE_QSTRINGBUILDER -DQT_NO_DEBUG -DQT_WEBKIT_LIB -DQT_XML_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED

Is this normal? Or is there something extra what needs to be done on Mac for C++11 to work?

like image 391
Petr Avatar asked Jun 27 '14 17:06

Petr


1 Answers

It is always better to include things explicitly and so, I would add this to the code:

#include <cstddef>

If that does not work that means you have a fundamental issue with your system, namely:

  • You do not use a recent enough standard library implementation (e.g. try libc++).
  • You do not have the C++11 and on compilation enabled.

As a quick and nasty workaround, you could do the typedef yourself of course, as follows:

namespace std {
    typedef decltype(nullptr) nullptr_t;
}

or without std, but this really ought to be the last resort, and usually it means you are doing something wrong.

like image 76
lpapp Avatar answered Sep 17 '22 19:09

lpapp