Consider unsigned long for non-u/U decimal literals (C90/C++03)
authorHubert Tong <hubert.reinterpretcast@gmail.com>
Mon, 8 Jun 2015 21:59:59 +0000 (21:59 +0000)
committerHubert Tong <hubert.reinterpretcast@gmail.com>
Mon, 8 Jun 2015 21:59:59 +0000 (21:59 +0000)
commit13234ae40db3d89fcd05a3b59f4e3e25133c4976
tree55a60cf1d6c497391efe9846fd158e7f3450dc0e
parent218a9593db8b42e4df8ae22b7f1836927aa972c6
Consider unsigned long for non-u/U decimal literals (C90/C++03)

Summary:
This modifies Clang to reflect that under pre-C99 ISO C, decimal
constants may have type `unsigned long` even if they do not contain `u`
or `U` in their suffix (C90 subclause 6.1.3.2 paragraph 5). The same is
done for C++ without C++11 which--because of undefined behaviour--allows
for behaviour compatible with ISO C90 in the case of an unsuffixed
decimal literal and is otherwise identical to C90 in its treatment of
integer literals (C++03 subclause 2.13.1 [lex.icon] paragraph 2).

Messages are added to the `c99-compat` and `c++11-compat` groups to warn
on such literals, since they behave differently under the newer
standards.

Fixes PR 16678.

Test Plan:
A new test file is added to exercise both pre-C99/C++11 and C99/C++11-up
on decimal literals with no suffix or suffixes `l`/`L` for both 32-bit
and 64-bit `long`.

In the file, 2^31 (being `INT_MAX+1`) is tested for the expected type
using `__typeof__` and multiple declarations of the same entity. 2^63
is similarly tested when it is within the range of `unsigned long`.

Preprocessor arithmetic tests are added to ensure consistency given
that Clang (like GCC) uses greater than 32 bits for preprocessor
arithmetic even when `long` and `unsigned long` is 32 bits and a
pre-C99/C++11 mode is in effect.

Tests added:
  test/Sema/PR16678.c

Reviewers: fraggamuffin, rsmith

Reviewed By: rsmith

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D9794

llvm-svn: 239356
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/PR16678.c [new file with mode: 0644]