From patchwork Tue Mar 13 15:07:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 885169 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-474658-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="CeMjCvx8"; 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 400yrW04j4z9sRN for ; Wed, 14 Mar 2018 02:07:22 +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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=ZUSK0sfinLM9Xe9oaSEpZsui3WUsbVSmeetg0ubs6QjQqtPqVR10X wbo4IOjnNCTIj4AiT4q0o/6mZ7/FLl78VYp7IvEHUGuTtgHQuxTPVEGygzgxHqFB DO5xIddOnBRYaHiV8GNjbNr2kStOBCrezXMLlBTFn2l9Ryx+rue40w= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=62qJnLbOEe/cTV2APq6CLrBk954=; b=CeMjCvx8gwrWTiIC+7/m 7oFyOmZL3QsjQXYGHUYTZeV96MV1FDnLyZsPvluUVlTWLWEkITiGQ4lfAl/ySrmn UO6VU/jIilyY3I339Ow2NrJsiURLDUwdatHowkVkm4+bNlQNrd0QOgpDWM1J8A6S zuVf6b0AuxeLQttWyEz+TXI= Received: (qmail 40886 invoked by alias); 13 Mar 2018 15:07:15 -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 40874 invoked by uid 89); 13 Mar 2018 15:07:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No 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, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= 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; Tue, 13 Mar 2018 15:07:12 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 231E9C05B03E for ; Tue, 13 Mar 2018 15:07:11 +0000 (UTC) Received: from redhat.com (ovpn-204-41.brq.redhat.com [10.40.204.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1B69F17B85; Tue, 13 Mar 2018 15:07:09 +0000 (UTC) Date: Tue, 13 Mar 2018 16:07:02 +0100 From: Marek Polacek To: GCC Patches , Jason Merrill Subject: C++ PATCH to fix another ICE with stray template code (PR c++/84596) Message-ID: <20180313150701.GQ3522@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) Here's another case of a template code leaking into cxx_constant_value. While I recently added the require_rvalue_constant_expression check, it doesn't help here, because the problem is that we have a MODOP_EXPR (a template code), whose op1 is a TRUNC_DIV_EXPR without a type, so it's considered dependent, so fold_non_dependent_expr doesn't do its job. I thought we might skip calling cxx_constant_value when processing a template; we've already given an error in any case. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2018-03-13 Marek Polacek PR c++/84596 * semantics.c (finish_static_assert): Don't call cxx_constant_value when processing a template. * g++.dg/cpp0x/static_assert15.C: New test. Marek diff --git gcc/cp/semantics.c gcc/cp/semantics.c index bb8b5953539..8680322a76c 100644 --- gcc/cp/semantics.c +++ gcc/cp/semantics.c @@ -8681,7 +8681,8 @@ finish_static_assert (tree condition, tree message, location_t location, else if (condition && condition != error_mark_node) { error ("non-constant condition for static assertion"); - if (require_rvalue_constant_expression (condition)) + if (!processing_template_decl + && require_rvalue_constant_expression (condition)) cxx_constant_value (condition); } input_location = saved_loc; diff --git gcc/testsuite/g++.dg/cpp0x/static_assert15.C gcc/testsuite/g++.dg/cpp0x/static_assert15.C index e69de29bb2d..dfb64ad5e1b 100644 --- gcc/testsuite/g++.dg/cpp0x/static_assert15.C +++ gcc/testsuite/g++.dg/cpp0x/static_assert15.C @@ -0,0 +1,10 @@ +// PR c++/84596 +// { dg-do compile { target c++11 } } + +template +struct a { + constexpr void b() { + int c; + static_assert(c %= 1, ""); // { dg-error "non-constant" } + } +};