aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-10-15 07:53:56 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2024-10-15 08:01:40 +0200
commitac615e10471f45031e69bd3eda6795dd8b75e4ad (patch)
treef17dbe8e2a438bf5ceeaed98db58989cf3118809 /gcc/c-family
parent384faebde257b0b5a0aa334718ef1b645d4c8d1e (diff)
downloadgcc-ac615e10471f45031e69bd3eda6795dd8b75e4ad.zip
gcc-ac615e10471f45031e69bd3eda6795dd8b75e4ad.tar.gz
gcc-ac615e10471f45031e69bd3eda6795dd8b75e4ad.tar.bz2
libcpp: Add -Wtrailing-blanks warning
Trailing blanks is something even git diff diagnoses; while it is a coding style issue, if it is so common that git diff diagnoses it, I think it could be useful to various projects to check that at compile time. Dunno if it should be included in -Wextra, currently it isn't, and due to tons of trailing whitespace in our sources, haven't enabled it for when building gcc itself either. Note, git diff also diagnoses indentation with tab following space, wonder if we couldn't have trivial warning options where one would simply ask for checking of indentation with no tabs, just spaces vs. indentation with tabs followed by spaces (but never tab width or more spaces in the indentation). I think that would be easy to do also on the libcpp side. Checking how much something should be exactly indented requires syntax analysis (at least some limited one) and can consider columns of first token on line, but what the exact indentation blanks were is something only libcpp knows. On Thu, Sep 19, 2024 at 08:17:24AM +0200, Richard Biener wrote: > Generally I like diagnosing this early. For the above I'd say -Wtrailing-whitespace= > with a set of things to diagnose (and a sane default - just spaces and tabs - for > -Wtrailiing-whitespace) would be nice. As for naming possibly follow the > is{space,blank,cntrl} character classifications? If those are a good > fit, that is. The patch currently allows blank (' ' '\t') and space (' ' '\t' '\f' '\v'), cntrl not yet added, not anything non-ASCII, but in theory could be added later (though, non-ASCII would be just for inside of comments, say non-breaking space etc. in the source is otherwise an error). 2024-10-15 Jakub Jelinek <jakub@redhat.com> libcpp/ * include/cpplib.h (struct cpp_options): Add cpp_warn_trailing_whitespace member. (enum cpp_warning_reason): Add CPP_W_TRAILING_WHITESPACE. * internal.h (struct _cpp_line_note): Document 'W' line note. * lex.cc (_cpp_clean_line): Add 'W' line note for trailing whitespace except for trailing whitespace after backslash. Formatting fix. (_cpp_process_line_notes): Emit -Wtrailing-whitespace diagnostics. Formatting fixes. (lex_raw_string): Clear type on 'W' notes. gcc/ * doc/invoke.texi (Wtrailing-whitespace): Document. gcc/c-family/ * c.opt (Wtrailing-whitespace=): New option. (Wtrailing-whitespace): New alias. * c.opt.urls: Regenerate. gcc/testsuite/ * c-c++-common/cpp/Wtrailing-whitespace-1.c: New test. * c-c++-common/cpp/Wtrailing-whitespace-2.c: New test. * c-c++-common/cpp/Wtrailing-whitespace-3.c: New test. * c-c++-common/cpp/Wtrailing-whitespace-4.c: New test. * c-c++-common/cpp/Wtrailing-whitespace-5.c: New test. * c-c++-common/cpp/Wtrailing-whitespace-6.c: New test. * c-c++-common/cpp/Wtrailing-whitespace-7.c: New test. * c-c++-common/cpp/Wtrailing-whitespace-8.c: New test. * c-c++-common/cpp/Wtrailing-whitespace-9.c: New test. * c-c++-common/cpp/Wtrailing-whitespace-10.c: New test.
Diffstat (limited to 'gcc/c-family')
-rw-r--r--gcc/c-family/c.opt20
-rw-r--r--gcc/c-family/c.opt.urls6
2 files changed, 26 insertions, 0 deletions
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 1f2e72a..f758d7b 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1466,6 +1466,26 @@ Wtraditional-conversion
C ObjC Var(warn_traditional_conversion) Warning
Warn of prototypes causing type conversions different from what would happen in the absence of prototype.
+Enum
+Name(warn_trailing_whitespace_kind) Type(int) UnknownError(argument %qs to %<-Wtrailing-whitespace=%> not recognized)
+
+EnumValue
+Enum(warn_trailing_whitespace_kind) String(none) Value(0)
+
+EnumValue
+Enum(warn_trailing_whitespace_kind) String(blank) Value(1)
+
+EnumValue
+Enum(warn_trailing_whitespace_kind) String(space) Value(2)
+
+Wtrailing-whitespace=
+C ObjC C++ ObjC++ CPP(cpp_warn_trailing_whitespace) CppReason(CPP_W_TRAILING_WHITESPACE) Enum(warn_trailing_whitespace_kind) Joined RejectNegative Var(warn_trailing_whitespace) Init(0) Warning
+Warn about trailing whitespace on lines except when in raw string literals.
+
+Wtrailing-whitespace
+C ObjC C++ ObjC++ Alias(Wtrailing-whitespace=,blank,none) Warning
+Warn about trailing whitespace on lines except when in raw string literals. Equivalent to Wtrailing-whitespace=blank when enabled or Wtrailing-whitespace=none when disabled.
+
Wtrigraphs
C ObjC C++ ObjC++ CPP(warn_trigraphs) CppReason(CPP_W_TRIGRAPHS) Var(cpp_warn_trigraphs) Init(2) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall)
Warn if trigraphs are encountered that might affect the meaning of the program.
diff --git a/gcc/c-family/c.opt.urls b/gcc/c-family/c.opt.urls
index b1593ef..c173809 100644
--- a/gcc/c-family/c.opt.urls
+++ b/gcc/c-family/c.opt.urls
@@ -864,6 +864,12 @@ UrlSuffix(gcc/Warning-Options.html#index-Wno-traditional)
Wtraditional-conversion
UrlSuffix(gcc/Warning-Options.html#index-Wno-traditional-conversion)
+Wtrailing-whitespace=
+UrlSuffix(gcc/Warning-Options.html#index-Wno-trailing-whitespace)
+
+Wtrailing-whitespace
+UrlSuffix(gcc/Warning-Options.html#index-Wno-trailing-whitespace)
+
Wtrigraphs
UrlSuffix(gcc/Warning-Options.html#index-Wtrigraphs)