C++ draft standard N4604

I just learned about the new C++ draft standard N4604.

I read Section 16.8 “Predefined macro names” and created this little test program to assess the compilers available:

#ifndef __cplusplus
#error not a conforming C++ compiler
#endif

#if __cplusplus >= 199711L

#include <iostream>
using namespace std;

#elif __cplusplus < 199711L

#include <iostream.h>

#endif

// last changed 2016-08-11 in accordance with the N4604 draft standard
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4604.pdf

int main()
{
  cout << "__cplusplus is " << __cplusplus << endl;

  cout << "__DATE__ is " << __DATE__ << endl;

  cout << "__FILE__ is " << __FILE__ << endl;

  cout << "__LINE__ is " << __LINE__ << endl;

#ifdef __STDC_HOSTED__
  cout << "__STDC_HOSTED__ is " << __STDC_HOSTED__ << endl;
#else
  cout << "__STDC_HOSTED__ is not defined" << endl;
#endif

  cout << "__TIME__ is " << __TIME__ << endl;

#ifdef __STDC__
  cout << "__STDC__ is " << __STDC__ << endl;
#else
  cout << "__STDC__ is not defined" << endl;
#endif

#ifdef __STDC_MB_MIGHT_NEQ_WC__
  cout << "__STDC_MB_MIGHT_NEQ_WC__ is " << __STDC_MB_MIGHT_NEQ_WC__ << endl;
#else
  cout << "__STDC_MB_MIGHT_NEQ_WC__ is not defined" << endl;
#endif

#ifdef __STDC_VERSION__
  cout << "__STDC_VERSION__ is " << __STDC_VERSION__ << endl;
#else
  cout << "__STDC_VERSION__ is not defined" << endl;
#endif

#ifdef __STDC_ISO_10646__
  cout << "__STDC_ISO_10646__ is " << __STDC_ISO_10646__ << endl;
#else
  cout << "__STDC_ISO_10646__ is not defined" << endl;
#endif

#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
  cout << "__STDCPP_DEFAULT_NEW_ALIGNMENT__ is " << __STDCPP_DEFAULT_NEW_ALIGNMENT__ << endl;
#else
  cout << "__STDCPP_DEFAULT_NEW_ALIGNMENT__ is not defined" << endl;
#endif

#ifdef __STDCPP_STRICT_POINTER_SAFETY__
  cout << "__STDCPP_STRICT_POINTER_SAFETY__ is " << __STDCPP_STRICT_POINTER_SAFETY__ << endl;
#else
  cout << "__STDCPP_STRICT_POINTER_SAFETY__ is not defined" << endl;
#endif

#ifdef __STDCPP_THREADS__
  cout << "__STDCPP_THREADS__ is " << __STDCPP_THREADS__ << endl;
#else
  cout << "__STDCPP_THREADS__ is not defined" << endl;
#endif

  return 0;
}

// stdcpp.cc

I compiled the source file with clang 3.8.1 and ran the executable:

~/c++/stdcpp $ clang++38 --version
clang version 3.8.1 (tags/RELEASE_381/final)
Target: x86_64-unknown-freebsd10.3
Thread model: posix
InstalledDir: /usr/local/llvm38/bin
~/c++/stdcpp $ clang++38 -o stdcpp -Wall -pedantic -O0 -g3 stdcpp.cc
~/c++/stdcpp $ ./stdcpp
__cplusplus is 199711
__DATE__ is Aug 11 2016
__FILE__ is stdcpp.cc
__LINE__ is 27
__STDC_HOSTED__ is 1
__TIME__ is 10:18:55
__STDC__ is 1
__STDC_MB_MIGHT_NEQ_WC__ is 1
__STDC_VERSION__ is not defined
__STDC_ISO_10646__ is not defined
__STDCPP_DEFAULT_NEW_ALIGNMENT__ is not defined
__STDCPP_STRICT_POINTER_SAFETY__ is not defined
__STDCPP_THREADS__ is not defined
~/c++/stdcpp $ clang++38 -o stdcpp -std=c++11 -Wall -pedantic -O0 -g3 stdcpp.cc
~/c++/stdcpp $ ./stdcpp
__cplusplus is 201103
__DATE__ is Aug 11 2016
__FILE__ is stdcpp.cc
__LINE__ is 27
__STDC_HOSTED__ is 1
__TIME__ is 10:19:08
__STDC__ is 1
__STDC_MB_MIGHT_NEQ_WC__ is 1
__STDC_VERSION__ is not defined
__STDC_ISO_10646__ is not defined
__STDCPP_DEFAULT_NEW_ALIGNMENT__ is not defined
__STDCPP_STRICT_POINTER_SAFETY__ is not defined
__STDCPP_THREADS__ is not defined
~/c++/stdcpp $ clang++38 -o stdcpp -std=c++14 -Wall -pedantic -O0 -g3 stdcpp.cc
~/c++/stdcpp $ ./stdcpp
__cplusplus is 201402
__DATE__ is Aug 11 2016
__FILE__ is stdcpp.cc
__LINE__ is 27
__STDC_HOSTED__ is 1
__TIME__ is 10:19:20
__STDC__ is 1
__STDC_MB_MIGHT_NEQ_WC__ is 1
__STDC_VERSION__ is not defined
__STDC_ISO_10646__ is not defined
__STDCPP_DEFAULT_NEW_ALIGNMENT__ is not defined
__STDCPP_STRICT_POINTER_SAFETY__ is not defined
__STDCPP_THREADS__ is not defined
~/c++/stdcpp $ clang++38 -o stdcpp -std=c++1z -Wall -pedantic -O0 -g3 stdcpp.cc
~/c++/stdcpp $ ./stdcpp
__cplusplus is 201406
__DATE__ is Aug 11 2016
__FILE__ is stdcpp.cc
__LINE__ is 27
__STDC_HOSTED__ is 1
__TIME__ is 10:19:31
__STDC__ is 1
__STDC_MB_MIGHT_NEQ_WC__ is 1
__STDC_VERSION__ is not defined
__STDC_ISO_10646__ is not defined
__STDCPP_DEFAULT_NEW_ALIGNMENT__ is not defined
__STDCPP_STRICT_POINTER_SAFETY__ is not defined
__STDCPP_THREADS__ is not defined

Leave a Reply

Your email address will not be published. Required fields are marked *