This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/60523] New: Warning flag for octal literals
- From: "david at westcontrol dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 14 Mar 2014 08:53:21 +0000
- Subject: [Bug c/60523] New: Warning flag for octal literals
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60523
Bug ID: 60523
Summary: Warning flag for octal literals
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: david at westcontrol dot com
It would be nice if there were a warning flag that triggered on octal literals.
Octal literals are rarely used in modern C and C++ code, but can easily be
introduced by mistake - "int x = 050;" appears at first reading to set x to 50,
but in C and C++ the leading 0 means it is interpreted as octal and therefore
sets x to 40 (decimal).
As octal literals are seldom useful, and often confusing or accidental, they
are banned by coding standards like MISRA. But as they are part of the
language defined by the C and C++ standards, and are used in some existing
code, they obviously cannot be removed. As a compromise, I would like to
propose the introduction of a warning flags "-Woctal" which would produce a
diagnostic message when a literal is interpreted as an octal number. Of
preference, this would be included in "-Wextra" (it probably should not be in
"-Wall", since octal literals are valid C and C++).