From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 112871 invoked by alias); 12 Oct 2018 01:28:44 -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 112853 invoked by uid 89); 12 Oct 2018 01:28:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1082 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; Fri, 12 Oct 2018 01:28:42 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2E5733082E71 for ; Fri, 12 Oct 2018 01:28:41 +0000 (UTC) Received: from redhat.com (ovpn-120-116.rdu2.redhat.com [10.10.120.116]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B0B9A89583; Fri, 12 Oct 2018 01:28:40 +0000 (UTC) Date: Fri, 12 Oct 2018 01:42:00 -0000 From: Marek Polacek To: GCC Patches , Jason Merrill Subject: C++ PATCH to add test to cover case RANGE_FOR_STMT Message-ID: <20181012012838.GL19003@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-SW-Source: 2018-10/txt/msg00711.txt.bz2 Recently it came up that no test in the testsuite triggers the RANGE_FOR_STMT case in potential_constant_expression_1. I came up with this valid test that tickles that codepath. I can't use ({ }) instead of a lambda because the constexpr machinery doesn't handle statement expressions; see default: in cxx_eval_constant_expression. Tested on x86_64-linux, ok for trunk? 2018-10-11 Marek Polacek * g++.dg/cpp1z/constexpr-lambda22.C: New test, diff --git gcc/testsuite/g++.dg/cpp1z/constexpr-lambda22.C gcc/testsuite/g++.dg/cpp1z/constexpr-lambda22.C index e69de29bb2d..8bb473431a5 100644 --- gcc/testsuite/g++.dg/cpp1z/constexpr-lambda22.C +++ gcc/testsuite/g++.dg/cpp1z/constexpr-lambda22.C @@ -0,0 +1,20 @@ +// { dg-do compile } +// { dg-options -std=c++17 } + +#define SA(X) static_assert((X),#X) + +template +constexpr int +foo () +{ + constexpr int a[] = { 1, 2, 3, 4, 5 }; + int i = 0; + auto j = [&] { + for (auto x : a) + i++; + return i; + }(); + return j; +} + +SA (foo() == 5);