Question about '<limits.h>' and availability of 'LLONG_MAX'

I was looking at an issue recently where a programmer was using 'LLONG_MAX'
in a program such as the following:

   #include <limits.h>
   int foo(long long x) { return x == LLONG_MAX; }

If this is a C program, then it compiles okay; but if it is a C++ program it
does not, though this was really simply fixed by adding '-std=c++11
-U__STRICT_ANSI__' to the options.

clang seems to default to a relaxed C90 if '-std=' is not used, so 'long
long' and 'LLONG_MAX' are available. Adding '-std=c90' results in a more
strict Standard violation error as expected.

But when compiled for C++ the equivalent relaxation does not happen and it
is an error even when '-std=' is not used

The test in '<limits.h>' (from 'clang/lib/Headers') is:

   #if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L

and I wonder would something like:

   #if !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901L ||
__cplusplus >= 201103L

be more consistent with how ISO Standards are enforced when '-std=' is not
used, and it would appear that this would align better with GCC too (though
GCC seems to also allow it when '-std=c++98' or '-std=c90' is selected which
I do not suggest 'clang' should follow).

Thanks,

  MartinO

I was looking at an issue recently where a programmer was using 'LLONG_MAX'
in a program such as the following:

  #include <limits.h>
  int foo(long long x) { return x == LLONG_MAX; }

If this is a C program, then it compiles okay; but if it is a C++ program it
does not, though this was really simply fixed by adding '-std=c++11
-U__STRICT_ANSI__' to the options.

clang seems to default to a relaxed C90 if '-std=' is not used, so 'long
long' and 'LLONG_MAX' are available.

You are incorrect there. For C sources, recent versions of clang
default to -std=gnu11 (except on PS4), and before that, the default was
always -std=gnu99. Under both, long long is available.

For C++, clang defaults to -std=gnu++98 (except again on PS4), and that
might be giving you grief. AFAIK C++98 does not officially know about
long long.

Adding '-std=c90' results in a more
strict Standard violation error as expected.

But when compiled for C++ the equivalent relaxation does not happen and it
is an error even when '-std=' is not used

The test in '<limits.h>' (from 'clang/lib/Headers') is:

  #if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L

and I wonder would something like:

  #if !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901L ||
__cplusplus >= 201103L

Does __STRICT_ANSI__ make any sense in regard to C++11 or higher?

-Dimitry