https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80648
Bug ID: 80648 Summary: Valid C++11 null pointer constant (1-1) is rejected Product: gcc Version: 7.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: Keith.S.Thompson at gmail dot com Target Milestone: --- I'm using g++ 7.1.0, built from source, on Ubuntu 16.10 x86_64. $ g++ --version g++ (GCC) 7.1.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ uname -a Linux bomb20 4.8.0-46-generic #49-Ubuntu SMP Fri Mar 31 13:57:14 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux $ Test case: int main() { void *p = 1-1; } When compiled with "g++ -std=c++03 -pedantic c.cpp", the compiler correctly doesn't complain; likewise with -std=c++98. With "g++ -std=c++11 -pedantic", it produces an error message: c.cpp: In function ‘int main()’: c.cpp:2:16: error: invalid conversion from ‘int’ to ‘void*’ [-fpermissive] void *p = 1-1; ~^~ And the same message with "g++ -std=c++14 -pedantic". C++14 restricted the definition of a null pointer constant. In the N4296 draft, 4.10p1 [conv.ptr] says: "A null pointer constant is an integer literal (2.13.2) with value zero or a prvalue of type std::nullptr_t." 1-1 is not an integer literal, so the error message is correct for C++14. But C++11 had not yet made that change. The C++11 standard, ISO/IEC 14882:2011(E), in the corresponding section, says: "A null pointer constant is an integral constant expression (5.19) prvalue of integer type that evaluates to zero or a prvalue of type std::nullptr_t." g++ correctly accepts 1-1 as a null pointer constant in C++98 and C++03 modes, and correctly rejects it in C++14 mode, but it should accept it in C++11 mode. (I do not of course suggest that using 1-1 as a null pointer constant is a good idea.)