diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c-family/c-opts.cc | 2 | ||||
-rw-r--r-- | gcc/c-family/c.opt | 19 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 25 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-1.c | 59 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-2.c | 60 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-3.c | 64 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-4.c | 41 |
7 files changed, 269 insertions, 1 deletions
diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index afb963d..6be65fb 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -1147,6 +1147,8 @@ c_common_post_options (const char **pfilename) flag_char8_t = (cxx_dialect >= cxx20) || flag_isoc23; cpp_opts->unsigned_utf8char = flag_char8_t ? 1 : cpp_opts->unsigned_char; + cpp_opts->cpp_tabstop = global_dc->m_tabstop; + if (flag_extern_tls_init) { if (!TARGET_SUPPORTS_ALIASES || !SUPPORTS_WEAK) diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index d5608ec..af79e4f 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -928,6 +928,25 @@ Wjump-misses-init C ObjC Var(warn_jump_misses_init) Warning LangEnabledby(C ObjC,Wc++-compat) Warn when a jump misses a variable initialization. +Enum +Name(warn_leading_whitespace_kind) Type(int) UnknownError(argument %qs to %<-Wleading-whitespace=%> not recognized) + +EnumValue +Enum(warn_leading_whitespace_kind) String(none) Value(0) + +EnumValue +Enum(warn_leading_whitespace_kind) String(spaces) Value(1) + +EnumValue +Enum(warn_leading_whitespace_kind) String(tabs) Value(2) + +EnumValue +Enum(warn_leading_whitespace_kind) String(blanks) Value(3) + +Wleading-whitespace= +C ObjC C++ ObjC++ CPP(cpp_warn_leading_whitespace) CppReason(CPP_W_LEADING_WHITESPACE) Enum(warn_leading_whitespace_kind) Joined RejectNegative Var(warn_leading_whitespace) Init(0) Warning +Warn about leading whitespace style issues on lines except when in raw string literals. + Wliteral-suffix C++ ObjC++ CPP(warn_literal_suffix) CppReason(CPP_W_LITERAL_SUFFIX) Var(cpp_warn_literal_suffix) Init(1) Warning Warn when a string or character literal is followed by a ud-suffix which does not begin with an underscore. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index aebcc90..6f94642 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -380,7 +380,8 @@ Objective-C and Objective-C++ Dialects}. -Winit-self -Winline -Wno-int-conversion -Wint-in-bool-context -Wno-int-to-pointer-cast -Wno-invalid-memory-model -Winvalid-pch -Winvalid-utf8 -Wno-unicode -Wjump-misses-init --Wlarger-than=@var{byte-size} -Wlogical-not-parentheses -Wlogical-op +-Wlarger-than=@var{byte-size} -Wleading-whitespace=@var{kind} +-Wlogical-not-parentheses -Wlogical-op -Wlong-long -Wno-lto-type-mismatch -Wmain -Wmaybe-uninitialized -Wmemset-elt-size -Wmemset-transposed-args -Wmisleading-indentation -Wmissing-attributes -Wmissing-braces @@ -8790,6 +8791,28 @@ those or trailing form feed or vertical tab characters. disables the warning, which is the default. This is a coding style warning. +@opindex Wleading-whitespace= +@item -Wleading-whitespace=@var{kind} +Warn about style issues in leading whitespace, but not about the amount of +indentation. Some projects use coding styles where only spaces are used +for indentation, others use only tabs, others use zero or more tabs (for +multiples of @code{-ftabstop=@var{n}}) followed by zero or fewer than @var{n} +spaces. No warning is emitted on lines which contain solely whitespace +(although @code{-Wtrailing-whitespace=} warning might be emitted), no +warnings are emitted inside of raw string literals. Warnings are also emitted +for leading whitespace inside of multi-line comments. +@code{-Wleading-whitespace=spaces} warns about leading whitespace other than +spaces for projects which want to indent just by spaces. +@code{-Wleading-whitespace=tabs} warns about leading whitespace other than +horizontal tabs for projects which want to indent just by horizontal tabs. +@code{-Wleading-whitespace=blanks} warns about leading whitespace other than +spaces and horizontal tabs, or about horizontal tab after a space in the +leading whitespace, or about @var{n} or more consecutive spaces in leading +whitespace (where @var{n} is argument of @code{-ftabstop=@var{n}}, 8 by +default). +@code{-Wleading-whitespace=none} disables the warning, which is the default. +This is a coding style warning. + @opindex Wtrampolines @opindex Wno-trampolines @item -Wtrampolines diff --git a/gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-1.c b/gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-1.c new file mode 100644 index 0000000..42ae76d --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-1.c @@ -0,0 +1,59 @@ +/* { dg-do compile { target { c || c++11 } } } */ +/* { dg-options "-Wleading-whitespace=blanks" } */ + + int i1; /* 4 spaces ok for -ftabstop=8 */ + int i2; /* 2 tabs 7 spaces ok for -ftabstop=8 */ + int i3; /* 8 spaces not ok */ +/* { dg-warning "too many consecutive spaces in leading whitespace" "" { target *-*-* } .-1 } */ + int i4; /* tab 8 spaces not ok */ +/* { dg-warning "too many consecutive spaces in leading whitespace" "" { target *-*-* } .-1 } */ + int i5; /* 4 spaces tab not ok */ +/* { dg-warning "tab after space in leading whitespace" "" { target *-*-* } .-1 } */ + int i6; /* space tab not ok */ +/* { dg-warning "tab after space in leading whitespace" "" { target *-*-* } .-1 } */ + int i7; /* tab vtab not ok */ +/* { dg-warning "whitespace other than spaces and tabs in leading whitespace" "" { target *-*-* } .-1 } */ + int i8; /* tab form-feed not ok */ +/* { dg-warning "whitespace other than spaces and tabs in leading whitespace" "" { target *-*-* } .-1 } */ + int i9; /* 4 spaces vtab not ok */ +/* { dg-warning "whitespace other than spaces and tabs in leading whitespace" "" { target *-*-* } .-1 } */ + int i10; /* 2 spaces form-feed not ok */ +/* { dg-warning "whitespace other than spaces and tabs in leading whitespace" "" { target *-*-* } .-1 } */ + +/* Just whitespace on a line is something for -Wtrailing-whitespace. */ +int \ + i11, \ + i12, \ + i13, \ + i14, \ + i15, \ + i16, \ + i17; +/* { dg-warning "too many consecutive spaces in leading whitespace" "" { target *-*-* } .-5 } */ +/* { dg-warning "too many consecutive spaces in leading whitespace" "" { target *-*-* } .-5 } */ +/* { dg-warning "tab after space in leading whitespace" "" { target *-*-* } .-5 } */ +/* { dg-warning "whitespace other than spaces and tabs in leading whitespace" "" { target *-*-* } .-5 } */ +/* { dg-warning "whitespace other than spaces and tabs in leading whitespace" "" { target *-*-* } .-5 } */ +/* { dg-warning "too many consecutive spaces in leading whitespace" "" { target *-*-* } .+1 } */ + const char *p = R"*|*( + a + b + c + d + e + f + g +)*|*"; +/* This is a comment with leading whitespace non-issues and issues + a + b + c + d + e + f + g +*/ +/* { dg-warning "too many consecutive spaces in leading whitespace" "" { target *-*-* } .-5 } */ +/* { dg-warning "tab after space in leading whitespace" "" { target *-*-* } .-5 } */ +/* { dg-warning "whitespace other than spaces and tabs in leading whitespace" "" { target *-*-* } .-5 } */ +/* { dg-warning "whitespace other than spaces and tabs in leading whitespace" "" { target *-*-* } .-5 } */ diff --git a/gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-2.c b/gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-2.c new file mode 100644 index 0000000..9def496 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-2.c @@ -0,0 +1,60 @@ +/* { dg-do compile { target { c || c++11 } } } */ +/* { dg-options "-Wleading-whitespace=spaces" } */ + + int i1; /* 4 spaces ok for */ + int i2; /* 2 tabs 7 spaces not ok */ +/* { dg-warning "whitespace other than spaces in leading whitespace" "" { target *-*-* } .-1 } */ + int i3; /* 8 spaces ok */ + int i4; /* tab 8 spaces not ok */ +/* { dg-warning "whitespace other than spaces in leading whitespace" "" { target *-*-* } .-1 } */ + int i5; /* 4 spaces tab not ok */ +/* { dg-warning "whitespace other than spaces in leading whitespace" "" { target *-*-* } .-1 } */ + int i6; /* space tab not ok */ +/* { dg-warning "whitespace other than spaces in leading whitespace" "" { target *-*-* } .-1 } */ + int i7; /* tab vtab not ok */ +/* { dg-warning "whitespace other than spaces in leading whitespace" "" { target *-*-* } .-1 } */ + int i8; /* tab form-feed not ok */ +/* { dg-warning "whitespace other than spaces in leading whitespace" "" { target *-*-* } .-1 } */ + int i9; /* 4 spaces vtab not ok */ +/* { dg-warning "whitespace other than spaces in leading whitespace" "" { target *-*-* } .-1 } */ + int i10; /* 2 spaces form-feed not ok */ +/* { dg-warning "whitespace other than spaces in leading whitespace" "" { target *-*-* } .-1 } */ + +/* Just whitespace on a line is something for -Wtrailing-whitespace. */ +int \ + i11, \ + i12, \ + i13, \ + i14, \ + i15, \ + i16, \ + i17; +/* { dg-warning "whitespace other than spaces in leading whitespace" "" { target *-*-* } .-7 } */ +/* { dg-warning "whitespace other than spaces in leading whitespace" "" { target *-*-* } .-6 } */ +/* { dg-warning "whitespace other than spaces in leading whitespace" "" { target *-*-* } .-5 } */ +/* { dg-warning "whitespace other than spaces in leading whitespace" "" { target *-*-* } .-5 } */ +/* { dg-warning "whitespace other than spaces in leading whitespace" "" { target *-*-* } .-5 } */ + const char *p = R"*|*( + a + b + c + d + e + f + g +)*|*"; +/* This is a comment with leading whitespace non-issues and issues + a + b + c + d + e + f + g +*/ +/* { dg-warning "whitespace other than spaces in leading whitespace" "" { target *-*-* } .-8 } */ +/* { dg-warning "whitespace other than spaces in leading whitespace" "" { target *-*-* } .-7 } */ +/* { dg-warning "whitespace other than spaces in leading whitespace" "" { target *-*-* } .-7 } */ +/* { dg-warning "whitespace other than spaces in leading whitespace" "" { target *-*-* } .-7 } */ +/* { dg-warning "whitespace other than spaces in leading whitespace" "" { target *-*-* } .-7 } */ +/* { dg-warning "whitespace other than spaces in leading whitespace" "" { target *-*-* } .-7 } */ diff --git a/gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-3.c b/gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-3.c new file mode 100644 index 0000000..5e42121 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-3.c @@ -0,0 +1,64 @@ +/* { dg-do compile { target { c || c++11 } } } */ +/* { dg-options "-Wleading-whitespace=tabs" } */ + + int i1; /* tab ok */ + int i2; /* 3 tabs ok */ + int i3; /* 8 spaces not ok */ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-1 } */ + int i4; /* tab 8 spaces not ok */ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-1 } */ + int i5; /* 4 spaces tab not ok */ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-1 } */ + int i6; /* space tab not ok */ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-1 } */ + int i7; /* tab vtab not ok */ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-1 } */ + int i8; /* tab form-feed not ok */ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-1 } */ + int i9; /* 4 spaces vtab not ok */ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-1 } */ + int i10; /* 2 spaces form-feed not ok */ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-1 } */ + int i20; /* 2 spaces not ok */ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-1 } */ + +/* Just whitespace on a line is something for -Wtrailing-whitespace. */ +int \ + i11, \ + i12, \ + i13, \ + i14, \ + i15, \ + i16, \ + i17; +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-6 } */ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-6 } */ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-6 } */ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-6 } */ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-6 } */ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-6 } */ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .+1 } */ + const char *p = R"*|*( + a + b + c + d + e + f + g +)*|*"; +/* This is a comment with leading whitespace non-issues and issues + a + b + c + d + e + f + g +*/ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-7 } */ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-7 } */ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-7 } */ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-7 } */ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-7 } */ +/* { dg-warning "whitespace other than tabs in leading whitespace" "" { target *-*-* } .-7 } */ diff --git a/gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-4.c b/gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-4.c new file mode 100644 index 0000000..1c4e9c0 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-4.c @@ -0,0 +1,41 @@ +/* { dg-do compile { target { c || c++11 } } } */ +/* { dg-options "-Wleading-whitespace=none" } */ + + int i1; /* tab ok */ + int i2; /* 3 tabs ok */ + int i3; /* 8 spaces ok */ + int i4; /* tab 8 spaces ok */ + int i5; /* 4 spaces tab ok */ + int i6; /* space tab ok */ + int i7; /* tab vtab ok */ + int i8; /* tab form-feed ok */ + int i9; /* 4 spaces vtab ok */ + int i10; /* 2 spaces form-feed ok */ + +/* Just whitespace on a line is something for -Wtrailing-whitespace. */ +int \ + i11, \ + i12, \ + i13, \ + i14, \ + i15, \ + i16, \ + i17; + const char *p = R"*|*( + a + b + c + d + e + f + g +)*|*"; +/* This is a comment with leading whitespace non-issues and issues + a + b + c + d + e + f + g +*/ |