libcpp, c-family, libstdc++: Add -Wdeprecated-octal-literal warning
GCC now warns about deprecated octal literals in C and C++ code.
A new warning, -Wdeprecated-octal-literal, has been added to GCC to flag the use of octal literals that do not use the 0o prefix. This change affects the C preprocessor (libcpp), C-family language frontends, and libstdc++. The warning is enabled by default for C++29 and can be configured for other C standards. The commit includes test cases demonstrating how to handle the warning, such as using the new 0o prefix or conditional compilation.
In Details
This commit introduces a new warning, -Wdeprecated-octal-literal, to discourage the use of traditional octal literals (e.g., 0123) in favor of the C++20 and C23 standard's 0o prefix (0o123). This impacts libcpp's lexical analysis and the frontends for C and C++. The warning is integrated into the respective language standards' parsing and is enabled by default for C++29. The implementation involves changes to tokenization and the diagnostic reporting mechanism.
- octal literal
- A numeric literal representing a number in base-8. Traditionally, these are written in C and C++ by prefixing the number with a zero (e.g.,
0177), but newer standards use0o(e.g.,0o177). - libcpp
- The C preprocessor used by the LLVM compiler toolchain, and also a component within GCC that handles preprocessor directives.
- C++29
- A future standard of the C++ programming language, following C++23.
- C23
- The latest standard of the C programming language, published in 2023.
- libstdc++
- The standard C++ library implementation used by GCC.