gcc/libcpp
Jakub Jelinek d4499a232a libcpp: Add -Wleading-whitespace= warning
The following patch on top of the r15-4346 patch adds
-Wleading-whitespace= warning option.
This warning doesn't care how much one actually indents which line
in the source (that is something that can't be easily done in the
preprocessor without doing syntactic analysis), but just simple checks
on what kind of whitespace is used in the indentation.
I think it is still useful to get warnings about such issues early,
while git diagnoses some of it in patches (e.g. the tab after space
case), getting the warnings earlier might help avoiding such issues
sooner.

There are projects which ban use of tabs and require just spaces,
others which require indentation just with horizontal tabs, and finally
projects which want indentation with tabs for multiples of tabstop size
followed by spaces (fewer than tabstop size), like GCC.
For all 3 kinds the warning diagnoses indentation with '\v' or '\f'
characters (unless line contains just whitespace), and for the last one
also cases where a space in the indentation is followed by horizontal
tab or where there are N or more consecutive spaces in the indentation
(for -ftabstop=N).

BTW, for additional testing I've enabled the warnings (without -Werror
for them) in stage3.  There are many warnings (both trailing and leading
whitespace), some of them something that can be easily fixed in the headers
or source files, but others with whitespace issues in generated sources,
so if we enable the warnings, either we'd need to adjust the generators
or disable the warnings in (some of the) generated files.

2024-10-23  Jakub Jelinek  <jakub@redhat.com>

libcpp/
	* include/cpplib.h (struct cpp_options): Add
	cpp_warn_leading_whitespace and cpp_tabstop members.
	(enum cpp_warning_reason): Add CPP_W_LEADING_WHITESPACE.
	* internal.h (struct _cpp_line_note): Document new
	line note kinds.
	* init.cc (cpp_create_reader): Set cpp_tabstop to 8.
	* lex.cc (find_leading_whitespace_issues): New function.
	(_cpp_clean_line): Use it.
	(_cpp_process_line_notes): Handle 'L', 'S' and 'T' line notes.
	(lex_raw_string): Clear type on 'L', 'S' and 'T' line notes
	inside of raw string literals.
gcc/
	* doc/invoke.texi (Wleading-whitespace=): Document.
gcc/c-family/
	* c.opt (Wleading-whitespace=): New option.
	* c-opts.cc (c_common_post_options): Set cpp_opts->cpp_tabstop
	to global_dc->m_tabstop.
gcc/testsuite/
	* c-c++-common/cpp/Wleading-whitespace-1.c: New test.
	* c-c++-common/cpp/Wleading-whitespace-2.c: New test.
	* c-c++-common/cpp/Wleading-whitespace-3.c: New test.
	* c-c++-common/cpp/Wleading-whitespace-4.c: New test.
2024-10-23 09:58:06 +02:00
..
include libcpp: Add -Wleading-whitespace= warning 2024-10-23 09:58:06 +02:00
po Daily bump. 2024-09-20 17:36:00 +00:00
aclocal.m4 libcpp: Regenerate aclocal.m4 and configure [PR 114748] 2024-04-17 14:08:34 +00:00
ChangeLog Daily bump. 2024-10-20 00:17:57 +00:00
ChangeLog.jit
charset.cc c, libcpp: Partially implement C2Y N3353 paper [PR117028] 2024-10-17 07:01:44 +02:00
combining-chars.inc diagnostics: add support for "text art" diagrams 2023-06-21 21:49:00 -04:00
config.in libcpp: replace SSE4.2 helper with an SSSE3 one 2024-08-20 14:09:12 +03:00
configure libcpp: replace SSE4.2 helper with an SSSE3 one 2024-08-20 14:09:12 +03:00
configure.ac libcpp: replace SSE4.2 helper with an SSSE3 one 2024-08-20 14:09:12 +03:00
directives.cc diagnostics: libcpp: Improve locations for _Pragma lexing diagnostics [PR114423] 2024-10-19 19:25:39 -04:00
errors.cc diagnostics: libcpp: Improve locations for _Pragma lexing diagnostics [PR114423] 2024-10-19 19:25:39 -04:00
expr.cc c, libcpp: Partially implement C2Y N3353 paper [PR117028] 2024-10-17 07:01:44 +02:00
files.cc libcpp, c, middle-end: Optimize initializers using #embed in C 2024-10-16 10:32:27 +02:00
generated_cpp_wcwidth.h contrib, libcpp, libstdc++: Update to Unicode 16.0 2024-10-08 10:01:47 +02:00
identifiers.cc Update copyright years. 2024-01-03 12:19:35 +01:00
init.cc libcpp: Add -Wleading-whitespace= warning 2024-10-23 09:58:06 +02:00
internal.h libcpp: Add -Wleading-whitespace= warning 2024-10-23 09:58:06 +02:00
lex.cc libcpp: Add -Wleading-whitespace= warning 2024-10-23 09:58:06 +02:00
line-map.cc diagnostics: SARIF output: potentially add escaped renderings of source (§3.3.4) 2024-07-24 18:07:54 -04:00
location-example.txt
macro.cc libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics 2024-10-12 10:50:41 +02:00
Makefile.in libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics 2024-10-12 10:50:41 +02:00
makeucnid.cc contrib, libcpp, libstdc++: Update to Unicode 16.0 2024-10-08 10:01:47 +02:00
makeuname2c.cc contrib, libcpp, libstdc++: Update to Unicode 16.0 2024-10-08 10:01:47 +02:00
mkdeps.cc c++: add module extensions 2024-05-29 09:48:05 -04:00
pch.cc libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics 2024-10-12 10:50:41 +02:00
printable-chars.inc diagnostics: add support for "text art" diagrams 2023-06-21 21:49:00 -04:00
symtab.cc Update copyright years. 2024-01-03 12:19:35 +01:00
system.h Update copyright years. 2024-01-03 12:19:35 +01:00
traditional.cc libcpp, genmatch: Use gcc_diag instead of printf for libcpp diagnostics 2024-10-12 10:50:41 +02:00
ucnid.h contrib, libcpp, libstdc++: Update to Unicode 16.0 2024-10-08 10:01:47 +02:00
ucnid.tab Update copyright years. 2024-01-03 12:19:35 +01:00
uname2c.h contrib, libcpp, libstdc++: Update to Unicode 16.0 2024-10-08 10:01:47 +02:00