On 2017/2/7 10:43, Xi Ruoyao wrote:
On 2017-02-06 Mon 21:49 +0000, Jason Mancini wrote:
Is this the expected behavior?
Yes. According to C++ Standard (ISO/IEC 14882:2011 2.5):
A preprocessing token is the minimal lexical element of the
language in translation phases 3 through 6. The categories of
preprocessing token are: header names, identifiers, ....., and
single non-white-space characters that do not lexically match the
other preprocessing token categories. If a ' or a " character matches
the last category, the behavior is *undefined*.
Then everything may happen.
That is incorrect. `1'b0` is a valid a preprocessing number token, in
spite that it is not valid. (See paragraph 4 after the one you quoted.)
The following program concatenates two invalid PP tokens, yielding a
valid PP integral token that has the value `0x1b0`:
#define Q 1'b0
#define P 0x
#define CAT(x,y) CAT_(x,y)
#define CAT_(x,y) x##y
#include <cstdio>
int main(){
std::printf("%x", CAT(P, Q));
}
This is because that, in C++14, "'" may be digit separators. The GCC
preprocessor can not detect "digit separator outside digit sequence"
at now. So there is no warnings. Maybe we should make an
enhancement to add this warning.
It isn't the preprocessor to blame. A preprocessing token isn't a token.
The preprocessor has no lexical and semantical knowledge about `integral
literals`.
--
Best regards,
ltpmouse