From patchwork Thu Jan 18 22:53:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 863203 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-471619-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="iOs5h8Z4"; dkim-atps=neutral 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 3zMzm360Wjz9sBd for ; Fri, 19 Jan 2018 09:54:11 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=UfAswCiaf3L1qLe6GyRlJHzmep6ovKVtoR3g4S6zj78RwKPWMh 4uWrkjOl5Ph5ruypzhfsNozTyhjccssUQCRW3PUVZn7t5yR6SIXSUWdxp4j8ZpCZ Pvuzr9TFcMTowhBdrSeaqheqVo57yveWD5mHG8U+tJNFAZEpQedeQRWPA= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=8/0ftDhJ179xL5Eq6/EcIo3NHWY=; b=iOs5h8Z4bKkxbkU7+XSK GgZUwgYbCpif6uaEF/tWovW3FTL/QZXr7Kpl9FDKdlYAkM/K23qHbLZamdGDMUbX sTANa3wCq55RtJPPLFcOJP1+LqaraJsJIsWT/rrX35FDr/rXt67m+uYFDQE94x1T cULXBXCHowoeOM4D18e9izU= Received: (qmail 51534 invoked by alias); 18 Jan 2018 22:54:02 -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 51410 invoked by uid 89); 18 Jan 2018 22:54:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=sk:stateme X-HELO: userp2120.oracle.com Received: from userp2120.oracle.com (HELO userp2120.oracle.com) (156.151.31.85) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 18 Jan 2018 22:53:59 +0000 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w0IMr2xP027841; Thu, 18 Jan 2018 22:53:55 GMT Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2fk4pg01d6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 18 Jan 2018 22:53:55 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w0IMrth3002457 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 18 Jan 2018 22:53:55 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w0IMrsbZ021793; Thu, 18 Jan 2018 22:53:54 GMT Received: from [192.168.1.4] (/79.33.231.147) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 18 Jan 2018 14:53:53 -0800 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill , Nathan Sidwell From: Paolo Carlini Subject: [C++ Patch] PR 83921 ("[7/8 Regression] GCC rejects constexpr initialization of empty aggregate") Message-ID: Date: Thu, 18 Jan 2018 23:53:50 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8778 signatures=668654 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801180296 X-IsSubscribed: yes Hi, I'm finishing testing on x86_64-linux the below - which anyway seems very unlikely to cause regressions because we aren't really stress testing the relevant checks in potential_constant_expression_1 much, if at all (surely stmtexpr19.C tests static). Anyway, the issue is the following. In 239268 aka "Implement C++17 constexpr lambda" Jason added some checks to potential_constant_expression_1 covering static, thread_local and uninitialized var declaration in constexpr function context. Then extended to constexpr context more generally in 249382 aka "constexpr and static var in statement-expression", with ext/stmtexpr19.C covering the static case. Now, it looks like the check for uninitialized vars in constexpr functions context is more correctly carried out by check_for_uninitialized_const_var instead, because the simple check in potential_constant_expression_1 as-is causes the regression pointed out by this bug. Thus the fix below which just restricts the check in potential_constant_expression_1, and the testcases, one for this bug proper, plus one, very similar to stmtexpr19.C, double checking that we are still diagnosing in the statement-expression context. I also verified under the debugger how for constexpr-83921.C we are actually running check_for_uninitialized_const_var on 'f' - which obviously passes. Thanks, Paolo. //////////////////////// /cp 2018-01-18 Paolo Carlini PR c++/83921 * constexpr.c (potential_constant_expression_1): Do not handle uninitialized vars in constexpr function here. /testsuite 2018-01-18 Paolo Carlini PR c++/83921 * g++.dg/cpp1y/constexpr-83921.C: New. * g++.dg/ext/stmtexpr20.C: Likewise. Index: cp/constexpr.c =================================================================== --- cp/constexpr.c (revision 256865) +++ cp/constexpr.c (working copy) @@ -5708,7 +5708,9 @@ potential_constant_expression_1 (tree t, bool want "% in % context", tmp); return false; } - else if (!DECL_NONTRIVIALLY_INITIALIZED_P (tmp)) + else if (!DECL_NONTRIVIALLY_INITIALIZED_P (tmp) + /* Handled in check_for_uninitialized_const_var. */ + && !var_in_constexpr_fn (tmp)) { if (flags & tf_error) error_at (DECL_SOURCE_LOCATION (tmp), "uninitialized " Index: testsuite/g++.dg/cpp1y/constexpr-83921.C =================================================================== --- testsuite/g++.dg/cpp1y/constexpr-83921.C (nonexistent) +++ testsuite/g++.dg/cpp1y/constexpr-83921.C (working copy) @@ -0,0 +1,7 @@ +// PR c++/83921 +// { dg-do compile { target c++14 } } + +struct Foo {}; +constexpr void test() { + Foo f; +} Index: testsuite/g++.dg/ext/stmtexpr20.C =================================================================== --- testsuite/g++.dg/ext/stmtexpr20.C (nonexistent) +++ testsuite/g++.dg/ext/stmtexpr20.C (working copy) @@ -0,0 +1,15 @@ +// PR c++/83921 +// { dg-options "" } +// { dg-do compile { target c++11 } } + +struct test { const int *addr; }; + +const test* setup() +{ + static constexpr test atest = + { + ({ int inner; &inner; }) // { dg-error "uninitialized" } + }; + + return &atest; +}