From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27887 invoked by alias); 8 Oct 2016 06:15:21 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 26401 invoked by uid 89); 8 Oct 2016 06:14:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.6 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=2016-10-08 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 08 Oct 2016 06:13:59 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 98908C054921 for ; Sat, 8 Oct 2016 06:13:57 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-44.ams2.redhat.com [10.36.116.44]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u986DsDo006006 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 8 Oct 2016 02:13:56 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id u986DrRd005509; Sat, 8 Oct 2016 08:13:53 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id u986DpP3005508; Sat, 8 Oct 2016 08:13:51 +0200 Date: Sat, 08 Oct 2016 06:15:00 -0000 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix -Wimplicit-fallthrough in templates (PR c++/77886) Message-ID: <20161008061350.GL7282@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes X-SW-Source: 2016-10/txt/msg00524.txt.bz2 Hi! As the testcase shows, we weren't copying over FALLTHROUGH_LABEL_P during instantiations, which means that // FALLTHROUGH comments in templates were ignored (while [[fallthrough]];, being represented as internal calls, worked fine). Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2016-10-08 Jakub Jelinek PR c++/77886 * pt.c (tsubst_expr) Copy over FALLTHROUGH_LABEL_P flag to the new LABEL_DECL. (tsubst_expr) : Likewise. * g++.dg/warn/Wimplicit-fallthrough-2.C: New test. --- gcc/cp/pt.c.jj 2016-10-07 21:36:47.000000000 +0200 +++ gcc/cp/pt.c 2016-10-07 23:51:53.244510627 +0200 @@ -15456,7 +15456,10 @@ tsubst_expr (tree t, tree args, tsubst_f { tree low = RECUR (CASE_LOW (t)); tree high = RECUR (CASE_HIGH (t)); - finish_case_label (EXPR_LOCATION (t), low, high); + tree l = finish_case_label (EXPR_LOCATION (t), low, high); + if (l && TREE_CODE (l) == CASE_LABEL_EXPR) + FALLTHROUGH_LABEL_P (CASE_LABEL (l)) + = FALLTHROUGH_LABEL_P (CASE_LABEL (t)); } break; @@ -15466,6 +15469,8 @@ tsubst_expr (tree t, tree args, tsubst_f tree label; label = finish_label_stmt (DECL_NAME (decl)); + if (TREE_CODE (label) == LABEL_DECL) + FALLTHROUGH_LABEL_P (label) = FALLTHROUGH_LABEL_P (decl); if (DECL_ATTRIBUTES (decl) != NULL_TREE) cplus_decl_attributes (&label, DECL_ATTRIBUTES (decl), 0); } --- gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-2.C.jj 2016-10-07 23:59:03.851102742 +0200 +++ gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-2.C 2016-10-08 00:04:25.759058055 +0200 @@ -0,0 +1,66 @@ +// PR c++/77886 +// { dg-do compile } +// { dg-options "-Wimplicit-fallthrough" } + +template +int +foo (int x, int y) +{ + switch (x) + { + case 1: + x++; // { dg-bogus "this statement may f\[ahlotu\]*gh" } + // FALLTHROUGH + case 2: + x++; + break; + case 3: + x++; // { dg-bogus "this statement may f\[ahlotu\]*gh" } + // FALLTHROUGH + lab: + case 4: + x++; + break; + case 5: + x++; // { dg-bogus "this statement may f\[ahlotu\]*gh" } + // FALLTHROUGH + default: + x++; + break; + case 26: + goto lab; + } +#if __cplusplus >= 201103L + switch (y) + { + case 1: + y++; // { dg-bogus "this statement may f\[ahlotu\]*gh" } + [[fallthrough]]; + case 2: + y++; + break; + case 3: + y++; // { dg-bogus "this statement may f\[ahlotu\]*gh" } + [[fallthrough]]; + lab2: + case 4: + y++; + break; + case 5: + y++; // { dg-bogus "this statement may f\[ahlotu\]*gh" } + [[fallthrough]]; + default: + y++; + break; + case 26: + goto lab2; + } +#endif + return x + y; +} + +int +bar (int x, int y) +{ + return foo<0> (x, y); +} Jakub