From patchwork Mon Feb 26 21:58:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 878158 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-473899-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="tRL8dl0O"; 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 3zqwhX27NWz9s1j for ; Tue, 27 Feb 2018 08:59:06 +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 :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=uN9fqHo0OjpTjR/T3XdwKmv0J1k7pXPFMiBzAZaD7P6lMK VJ2O5CokR6bFJt/HRBhBHyJVbDlpmE9iTM3ZLU0H58ITXZbsdOr/8Sc7V4qYoBe7 H7clT2F46UIrAnz38vzcEYS8azRqWQr6pcOLatvNJAtyOkSZgvxR754Rd4uDs= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=9hBdA5oJsLbSmVcwSmi3srSkvpw=; b=tRL8dl0OfVknW7js6+T3 CwQBVZ92+jrYbirocPg+BJ+F3wJoiVjPi7IWnBXNmKGIOnoBg1QQ+yTCgFB6fm/E UtYwHwe0TQhBofq3Q5Ja/kRcy9xVSCZe9JhpBMHDfVVjZZsBNcOhfRFvaQBxTH6Q R4Opyura51JNW3JuHKhvN7E= Received: (qmail 10739 invoked by alias); 26 Feb 2018 21:59:00 -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 10707 invoked by uid 89); 26 Feb 2018 21:58:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy= X-HELO: mail-io0-f172.google.com Received: from mail-io0-f172.google.com (HELO mail-io0-f172.google.com) (209.85.223.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 26 Feb 2018 21:58:58 +0000 Received: by mail-io0-f172.google.com with SMTP id q24so11626479ioh.8 for ; Mon, 26 Feb 2018 13:58:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=NSnTnOaHwJfQeGqZJLitfDeFU80e82PGam3lf0ZNqvA=; b=F4JKeCLQ0WDEl65cGVB35dM+27Dt80fWFv/gKn4g9//1BG//wKPs4Q5iSMo9APN0d1 Njvt8DSv/TZVQAKLr/WE3P+kB20CVHEZG8vCS1CUPKpLJf4MtpUlSGiHMm8yCMXO+5+i ms5kQbb895ZEccAM+/k5Gu+wl7Yf8Iby7mekCU/D71TAtyH42nvPBAKritEqj8DNb8Ph kVc3AT6TPtim3wkZv064oqm31EhLeyJOAyjaSGZk+WsLumPqDXFzet3ekwtsEKghCybH 2riI+ozsSQT7YVJc1WxlSBJCceqNyLrjyZvYDNHEpWKeeoNYSZ2XXzxajVAuIJEIsK6e sx0Q== X-Gm-Message-State: APf1xPBZXBR3zTEFbD1NQ9UqqpJu1ObH8ru0Lb1+c8wNADJGTR63TXeM azU5TQLQTLXsgtkgTpCwiXr2fypJHxv5fbGmekAWK9Wy X-Google-Smtp-Source: AG47ELsUMjhGkF43Wv0PzDps0NkDVkavyfDUMWR4ElGKK25RSnAagxe2bVBARmMfMLEyl8Y9iszdqtMpitFN0ZJfmQU= X-Received: by 10.107.7.87 with SMTP id 84mr13839999ioh.216.1519682336128; Mon, 26 Feb 2018 13:58:56 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.17.200 with HTTP; Mon, 26 Feb 2018 13:58:35 -0800 (PST) From: Jason Merrill Date: Mon, 26 Feb 2018 16:58:35 -0500 Message-ID: Subject: C++ PATCH for c++/84559, ICE with constexpr VLA To: gcc-patches List X-IsSubscribed: yes Clang rejects this testcase saying that the VLA is a non-literal type, but I think we don't want that; we want to allow VLAs in a constexpr function, where the length can be constant during constexpr evaluation. In this case, however, we are dealing with a constexpr variable rather than a variable in a constexpr function, so we want to reject the VLA. Tested x86_64-pc-linux-gnu, applying to trunk. commit d63c30c86d45831f20c4dc35f4ffaac2cfdd2588 Author: Jason Merrill Date: Mon Feb 26 15:32:32 2018 -0500 PR c++/84559 - ICE with constexpr VLA. * constexpr.c (ensure_literal_type_for_constexpr_object): Check for constexpr variable with VLA type. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 26d0d099a05..92b13219215 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -112,6 +112,13 @@ ensure_literal_type_for_constexpr_object (tree decl) cp_function_chain->invalid_constexpr = true; } } + else if (DECL_DECLARED_CONSTEXPR_P (decl) + && variably_modified_type_p (type, NULL_TREE)) + { + error ("% variable %qD has variably-modified type %qT", + decl, type); + decl = error_mark_node; + } } return decl; } diff --git a/gcc/testsuite/g++.dg/ext/constexpr-vla5.C b/gcc/testsuite/g++.dg/ext/constexpr-vla5.C new file mode 100644 index 00000000000..565d40ab077 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/constexpr-vla5.C @@ -0,0 +1,7 @@ +// PR c++/84559 +// { dg-do compile { target c++11 } } + +void foo(int i) +{ + constexpr char x[i] = ""; // { dg-error "" } +}