From patchwork Wed Sep 23 01:37:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 521532 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E348D140081 for ; Wed, 23 Sep 2015 11:37:46 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=bjHMdDtL; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=Gn1yERlpLxzt Fep4+HUOnrgVBbNo5LfrzlSSlssRvqlKql+480dAt35bMcSP50OelW6Z517wYvw5 70VTtrpYj4Eb6RhMAHg0XBzt50nsZE8Rh1fcSSB7SpvKSeYGp00R/2/MgkZLu0qj 5vapLcxYYsXRed8rgPU8kTAA/KTJP/w= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=GDXEQSU9gkfdqMHGH5 5zN170/tQ=; b=bjHMdDtLsKDTTCKPA2Rtj5jQzhapYInu7/amzpgK0ptRYgu36z aqO4LMBsnAifnV9Df8mpYA3pD0goD4qUHGzegFbTr8isJDJ2h3o2flom3xXtDJwl XSUm4OSX+HSD4Q4py35ss3lgxE+PmD1E4VdRS8xCX34H32SfyGSd935yY= Received: (qmail 25263 invoked by alias); 23 Sep 2015 01:37:37 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 25249 invoked by uid 89); 23 Sep 2015 01:37:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.2 required=5.0 tests=AWL, BAYES_50, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-qk0-f171.google.com Received: from mail-qk0-f171.google.com (HELO mail-qk0-f171.google.com) (209.85.220.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 23 Sep 2015 01:37:36 +0000 Received: by qkfq186 with SMTP id q186so12004387qkf.1 for ; Tue, 22 Sep 2015 18:37:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=P7bdWo+DM0UJ12vjRQjZbp36SyxNIePVUlbM+l1abCI=; b=lm3boZK2CegmZrSXFCH1VPQ4M8iZGzmZ3cGgbwNO9wiVH/rrSVuXOnkl/exCauyi0R 50R3aSBiPUrZ6Hj0Tb//GsT6fc/HyEgjLfvPB+qWOcpqGrfMygOKE1wNvAg9m9q0toJh 2YiYjaS8z8//uEYVlkxA7ZfC8ka7jEiVnLwYeP1psP9qlqLWJCO5uorTGkkiz2+xkgk1 B7L49pq0T4g62RJ+dSpq3uqhEvCjS4kPRnlvMaE0ZjLlktAFrvd6Ptkk5kWLDds6YtLq 53r/rhZZ+FQ93QR7xl4BMkubgL/EQ5xEMBVMKSDFoS+j0+uKJDV87/yv6Uk4IswInu9h JUTg== X-Gm-Message-State: ALoCoQlTMwagSsmM9a1XPboQ+j5V820ZGBBJuAd0qHXBjzl/JXviwR7F+SXLyWXiVvdADa+d4g1f X-Received: by 10.55.201.13 with SMTP id q13mr33329361qki.50.1442972253854; Tue, 22 Sep 2015 18:37:33 -0700 (PDT) Received: from localhost.localdomain (ool-4353acd8.dyn.optonline.net. [67.83.172.216]) by smtp.gmail.com with ESMTPSA id n10sm1712011qki.24.2015.09.22.18.37.32 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Sep 2015 18:37:32 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: Patrick Palka Subject: [PATCH] Fix a -Wmisleading-indentation false-negative Date: Tue, 22 Sep 2015 21:37:27 -0400 Message-Id: <1442972247-21681-1-git-send-email-patrick@parcs.ath.cx> We currently correctly emit a -Wmisleading-indentation warning for the code ... if (flagB); { foo (); } but we fail to emit a warning for the syntactically similar code ... else if (flagB); { foo (); } because in the heuristic in question we are inspecting the column of the guard token when we should rather be inspecting the column of the first non-whitespace character on the guard line. This patch adjusts the heuristic accordingly, making it consistently use guard_line_first_nws. Tested by building the linux, git, vim, sqlite and gdb-binutils sources with -Wmisleading-indentation. Is this OK after a bootstrap + regtest? gcc/c-family/ChangeLog: * c-indentation.c (should_warn_for_misleading_indentation): Compare next_stmt_vis_column with guard_line_first_nws instead of with guard_line_vis_column. gcc/testsuite/ChangeLog: * c-c++-common/Wmisleading-indentation.c: Augment test. --- gcc/c-family/c-indentation.c | 2 +- gcc/testsuite/c-c++-common/Wmisleading-indentation.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/gcc/c-family/c-indentation.c b/gcc/c-family/c-indentation.c index 5316316..5b119f7 100644 --- a/gcc/c-family/c-indentation.c +++ b/gcc/c-family/c-indentation.c @@ -464,7 +464,7 @@ should_warn_for_misleading_indentation (const token_indent_info &guard_tinfo, { if (next_stmt_vis_column > guard_line_first_nws || (next_tok_type == CPP_OPEN_BRACE - && next_stmt_vis_column == guard_vis_column)) + && next_stmt_vis_column == guard_line_first_nws)) return true; } } diff --git a/gcc/testsuite/c-c++-common/Wmisleading-indentation.c b/gcc/testsuite/c-c++-common/Wmisleading-indentation.c index f61c182..00c0a50 100644 --- a/gcc/testsuite/c-c++-common/Wmisleading-indentation.c +++ b/gcc/testsuite/c-c++-common/Wmisleading-indentation.c @@ -797,6 +797,15 @@ fn_37 (void) i++); foo (i); /* { dg-warning "statement is indented as if" } */ + if (flagA) + { + foo (1); + } + else if (flagB); /* { dg-message "8: ...this 'if' clause" } */ + { /* { dg-warning "statement is indented as if" } */ + foo (2); + } + #undef EMPTY #undef FOR_EACH }