From patchwork Tue Sep 24 17:31:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1989010 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=evy5inxB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XCn3y0BB5z1xst for ; Wed, 25 Sep 2024 03:32:13 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A60193858D37 for ; Tue, 24 Sep 2024 17:32:11 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id E75363858D28 for ; Tue, 24 Sep 2024 17:31:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E75363858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E75363858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727199110; cv=none; b=ZZVO7XjqQ8ubn0Jne3eENqqUC5fcpPJnyGK+cZEpayUgHrKpHDKKdTnAinZqO2xgy/b1cEC8luzfKmeBTj/j9OuGcJjoc6Ldv/eZ8ef4Un945lcRMb7NlZq3ZJg6S+5nDYSWzthRl3p69hf/YhmRlD3A2e7aaaZn46L8mVIyfKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727199110; c=relaxed/simple; bh=YwiWJRu7Cky72iUT8WGZJSHqtHfL14NqGxPbVdmwhEk=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=qdVN5WwTx/rmQ9tgEZyzjlyM/v9Fpa8Ox2RXeNZmRD9oBqeHF+Go06iyGD6DF51zw2cMwolOqI72BaDrcNT4fGUrplr0ZXKwAMEFrWyHVdAr/Iq9lnSqMxg97FJyxR/SIrCl44FXmDn8Ay1bvx9tR/Ge7Dz69kwusNd/u9QCLSA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727199106; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GomPt2LPSQd3bCDiM8RrNfh3xzgoxdsGxZmKkpOusS4=; b=evy5inxBC/FgoAp2zHrRe1IN45CVnTQBI4F8mHCMjElHq96JO+Rlx0ydxlV/Hg0lZTB13r CGrXenQc5j7mlZfh6EvQ2aaF+tH9kW07doI5ytmHpmViwNa75rN0zUyfemK4/Noo1XspfD 6pBocGAHhdzzQejGNpe+LHqo0dLK75A= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-361-ZO2_65V8NBaYv0gIL1SCwA-1; Tue, 24 Sep 2024 13:31:45 -0400 X-MC-Unique: ZO2_65V8NBaYv0gIL1SCwA-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 48A201903095 for ; Tue, 24 Sep 2024 17:31:44 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.61]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4ED0419560A3; Tue, 24 Sep 2024 17:31:43 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 48OHVe5R1118679 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 24 Sep 2024 19:31:40 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 48OHVekL1118678; Tue, 24 Sep 2024 19:31:40 +0200 Date: Tue, 24 Sep 2024 19:31:39 +0200 From: Jakub Jelinek To: "Joseph S. Myers" , Marek Polacek , Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] libcpp: Add -Wleading-whitespace= warning Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! The following patch on top of the https://gcc.gnu.org/pipermail/gcc-patches/2024-September/663388.html 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). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 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-09-24 Jakub Jelinek 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. Jakub --- libcpp/include/cpplib.h.jj 2024-09-23 16:08:40.846050280 +0200 +++ libcpp/include/cpplib.h 2024-09-23 17:09:32.250056701 +0200 @@ -594,9 +594,15 @@ struct cpp_options /* True if -finput-charset= option has been used explicitly. */ bool cpp_input_charset_explicit; + /* -Wleading-whitespace= value. */ + unsigned char cpp_warn_leading_whitespace; + /* -Wtrailing-whitespace= value. */ unsigned char cpp_warn_trailing_whitespace; + /* -ftabstop= value. */ + unsigned int cpp_tabstop; + /* Dependency generation. */ struct { @@ -713,6 +719,7 @@ enum cpp_warning_reason { CPP_W_BIDIRECTIONAL, CPP_W_INVALID_UTF8, CPP_W_UNICODE, + CPP_W_LEADING_WHITESPACE, CPP_W_TRAILING_WHITESPACE }; --- libcpp/internal.h.jj 2024-09-23 16:08:40.846050280 +0200 +++ libcpp/internal.h 2024-09-23 18:19:46.642467051 +0200 @@ -318,7 +318,8 @@ struct _cpp_line_note /* Type of note. The 9 'from' trigraph characters represent those trigraphs, '\\' an escaped newline, ' ' an escaped newline with - intervening space, 'W' trailing whitespace, 0 represents a note that + intervening space, 'W' trailing whitespace, 'L', 'S' and 'T' for + leading whitespace issues, 0 represents a note that has already been handled, and anything else is invalid. */ unsigned int type; }; --- libcpp/init.cc.jj 2024-09-20 08:57:03.041075703 +0200 +++ libcpp/init.cc 2024-09-23 17:24:53.564421636 +0200 @@ -246,6 +246,7 @@ cpp_create_reader (enum c_lang lang, cpp CPP_OPTION (pfile, cpp_warn_invalid_utf8) = 0; CPP_OPTION (pfile, cpp_warn_unicode) = 1; CPP_OPTION (pfile, cpp_input_charset_explicit) = 0; + CPP_OPTION (pfile, cpp_tabstop) = 8; /* Default CPP arithmetic to something sensible for the host for the benefit of dumb users like fix-header. */ --- libcpp/lex.cc.jj 2024-09-23 16:08:40.847050267 +0200 +++ libcpp/lex.cc 2024-09-24 09:32:57.293210930 +0200 @@ -818,6 +818,59 @@ _cpp_init_lexer (void) #endif } +/* Look for leading whitespace style issues on lines which don't contain + just whitespace. + For -Wleading-whitespace=spaces report if such lines contain leading + whitespace other than spaces. + For -Wleading-whitespace=tabs report if such lines contain leading + whitespace other than tabs. + For -Wleading-whitespace=blanks report if such lines contain leading + whitespace other than spaces+tabs, or contain in it tab after space, + or -ftabstop= or more consecutive spaces. */ + +static void +find_leading_whitespace_issues (cpp_reader *pfile, const uchar *s) +{ + const unsigned char *p = NULL; + uchar type = 'L'; + switch (CPP_OPTION (pfile, cpp_warn_leading_whitespace)) + { + case 1: /* spaces */ + while (*s == ' ') + ++s; + break; + case 2: /* tabs */ + while (*s == '\t') + ++s; + break; + case 3: /* blanks */ + while (*s == '\t') + ++s; + int n; + n = CPP_OPTION (pfile, cpp_tabstop); + while (*s == ' ') + { + if (--n == 0) + break; + ++s; + } + if (*s == '\t') + type = 'T'; /* Tab after space. */ + else if (*s == ' ') + type = 'S'; /* Too many spaces. */ + break; + default: + abort (); + } + if (!IS_NVSPACE (*s)) + return; + p = s++; + while (IS_NVSPACE (*s)) + ++s; + if (*s != '\n' && *s != '\r') + add_line_note (pfile->buffer, p, type); +} + /* Returns with a logical line that contains no escaped newlines or trigraphs. This is a time-critical inner loop. */ void @@ -836,6 +889,10 @@ _cpp_clean_line (cpp_reader *pfile) if (!buffer->from_stage3) { const uchar *pbackslash = NULL; + bool leading_ws_done = true; + + if (CPP_OPTION (pfile, cpp_warn_leading_whitespace)) + find_leading_whitespace_issues (pfile, s); /* Fast path. This is the common case of an un-escaped line with no trigraphs. The primary win here is by not writing any @@ -906,6 +963,7 @@ _cpp_clean_line (cpp_reader *pfile) add_line_note (buffer, p - 1, p != d ? ' ' : '\\'); d = p - 2; buffer->next_line = p - 1; + leading_ws_done = false; slow_path: while (1) @@ -915,6 +973,10 @@ _cpp_clean_line (cpp_reader *pfile) if (c == '\n' || c == '\r') { + if (CPP_OPTION (pfile, cpp_warn_leading_whitespace) + && !leading_ws_done) + find_leading_whitespace_issues (pfile, buffer->next_line); + /* Handle DOS line endings. */ if (c == '\r' && s != buffer->rlimit && s[1] == '\n') s++; @@ -931,9 +993,17 @@ _cpp_clean_line (cpp_reader *pfile) add_line_note (buffer, p - 1, p != d ? ' ' : '\\'); d = p - 2; buffer->next_line = p - 1; + leading_ws_done = false; } else if (c == '?' && s[1] == '?' && _cpp_trigraph_map[s[2]]) { + if (CPP_OPTION (pfile, cpp_warn_leading_whitespace) + && !leading_ws_done) + { + find_leading_whitespace_issues (pfile, buffer->next_line); + leading_ws_done = true; + } + /* Add a note regardless, for the benefit of -Wtrigraphs. */ add_line_note (buffer, d, s[2]); if (CPP_OPTION (pfile, trigraphs)) @@ -1073,6 +1143,39 @@ _cpp_process_line_notes (cpp_reader *pfi cpp_warning_with_line (pfile, CPP_W_TRAILING_WHITESPACE, pfile->line_table->highest_line, col, "trailing whitespace"); + else if (note->type == 'S') + cpp_warning_with_line (pfile, CPP_W_LEADING_WHITESPACE, + pfile->line_table->highest_line, col, + "too many consecutive spaces in leading " + "whitespace"); + else if (note->type == 'T') + cpp_warning_with_line (pfile, CPP_W_LEADING_WHITESPACE, + pfile->line_table->highest_line, col, + "tab after space in leading whitespace"); + else if (note->type == 'L') + switch (CPP_OPTION (pfile, cpp_warn_leading_whitespace)) + { + case 1: + cpp_warning_with_line (pfile, CPP_W_LEADING_WHITESPACE, + pfile->line_table->highest_line, col, + "whitespace other than spaces in leading " + "whitespace"); + break; + case 2: + cpp_warning_with_line (pfile, CPP_W_LEADING_WHITESPACE, + pfile->line_table->highest_line, col, + "whitespace other than tabs in leading " + "whitespace"); + break; + case 3: + cpp_warning_with_line (pfile, CPP_W_LEADING_WHITESPACE, + pfile->line_table->highest_line, col, + "whitespace other than spaces and tabs in " + "leading whitespace"); + break; + default: + abort (); + } else if (note->type == 0) /* Already processed in lex_raw_string. */; else @@ -2565,7 +2668,11 @@ lex_raw_string (cpp_reader *pfile, cpp_t break; case 'W': - /* Don't warn about trailing whitespace in raw string literals. */ + case 'L': + case 'S': + case 'T': + /* Don't warn about leading or trailing whitespace in raw string + literals. */ note->type = 0; note++; break; --- gcc/doc/invoke.texi.jj 2024-09-23 16:08:40.852050198 +0200 +++ gcc/doc/invoke.texi 2024-09-24 10:22:37.160401597 +0200 @@ -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 @@ -9021,6 +9022,28 @@ those or trailing form feed or vertical 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 --- gcc/c-family/c.opt.jj 2024-09-23 16:08:40.852050198 +0200 +++ gcc/c-family/c.opt 2024-09-23 16:28:01.465121547 +0200 @@ -920,6 +920,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. --- gcc/c-family/c-opts.cc.jj 2024-09-21 12:28:13.254943465 +0200 +++ gcc/c-family/c-opts.cc 2024-09-23 18:31:35.436871595 +0200 @@ -1135,6 +1135,8 @@ c_common_post_options (const char **pfil 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) --- gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-1.c.jj 2024-09-23 18:36:48.200659763 +0200 +++ gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-1.c 2024-09-23 20:20:50.305445775 +0200 @@ -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 } */ --- gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-2.c.jj 2024-09-23 20:28:31.071149603 +0200 +++ gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-2.c 2024-09-23 20:37:18.485944351 +0200 @@ -0,0 +1,60 @@ +/* { dg-do compile { target { c || c++11 } } } */ +/* { dg-options "-Wleading-whitespace=spaces" } */ + + int i1; /* 4 spaces ok for -ftabstop=8 */ + int i2; /* 2 tabs 7 spaces not ok for -ftabstop=8 */ +/* { 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 } */ --- gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-3.c.jj 2024-09-24 09:47:56.258877077 +0200 +++ gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-3.c 2024-09-24 10:00:47.686320005 +0200 @@ -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 } */ --- gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-4.c.jj 2024-09-24 09:50:06.693092007 +0200 +++ gcc/testsuite/c-c++-common/cpp/Wleading-whitespace-4.c 2024-09-24 09:50:40.153634079 +0200 @@ -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 +*/