Re: define and single quotes and C++11 vs 14

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

> There doesn't seem to be a selective -Wno-* flag for this warning. 

It it a preprocessor warning. We can suppress preprocessor warnings by

    g++ foo.cc -std=c++11 -Wp,-w -no-integrated-cpp

> C++11 mode rejects the code, while C++14 mode accepts the code, and
> g++ -E shows Q to be 1'b0 in that case.

> source code:
> ----------------------
> #define Q 1'b0
> ----------------------
> 
> # g++-6.3 -Werror -c src.cc -std=c++14

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.

> # g++-6.3 -Werror -c src.cc -std=c++11
> error: missing terminating ' character [-Werror]

In C++11, "'" can only indicate a character literal. GCC preprocessor
can easily detect "missing terminating ' character".

-- 
Xi Ruoyao <ryxi@xxxxxxxxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux