From patchwork Wed Aug 3 19:49:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 655586 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3s4P0F0n4yz9sRZ for ; Thu, 4 Aug 2016 05:54:01 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=k0uJBYEt; dkim-atps=neutral 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=X9rgBfaYWW/t2Dn6bkCWzdk9fV8KYM3XCeotoLJzEJT0KedcasR6l 0yQGegAM/Fr3ghnMrC5kZLfh0bAkjbCKfkE/7SlOTzX1fm8yHyCmceAic6AWF/CI C53OBIIeYZ9TBbhtalDpCjJaq+h6sCfguq9rG0YA1eBKPc8E/4L+R8= 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=jgmxeAIy6quPwXQdxZ6qVWuXdjk=; b=k0uJBYEtIaYXi7GBepMr 2DeDSwPWtXAwmw6jm/Kp8WGwa2m798wfhLCwVklfa2GPO4gVZx18+wCy+GFX0q+4 JNr7MQ7EhvQlIzPvFTsccMIigUMXvYqDy4lpS6Si610V03DEBtV/pbua96/GsIbT 64IGT/UPLhPbN3134hww04E= Received: (qmail 30350 invoked by alias); 3 Aug 2016 19:49:23 -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 29917 invoked by uid 89); 3 Aug 2016 19:49:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=sk:polacek, polacek@redhat.com, U*polacek, polacekredhatcom 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 03 Aug 2016 19:49:21 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 C6D6081112 for ; Wed, 3 Aug 2016 19:49:19 +0000 (UTC) Received: from redhat.com (ovpn-204-40.brq.redhat.com [10.40.204.40]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u73JnF5b026030 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 3 Aug 2016 15:49:17 -0400 Date: Wed, 3 Aug 2016 21:49:15 +0200 From: Marek Polacek To: GCC Patches , Jason Merrill Subject: C++ PATCH to allow constexpr ctor with typedef declaration in C++11 (c++/70229) Message-ID: <20160803194915.GE7007@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.6.2 (2016-07-01) In C++11, constexpr constructor must have an empty body except for several cases, one of them being: - typedef declarations and alias-declarations that do not define classes or enumerations But we were rejecting constexpr constructors consisting of a typedef declaration only. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2016-08-03 Marek Polacek PR c++/70229 * constexpr.c (check_constexpr_ctor_body_1): Allow typedef declarations. * g++.dg/cpp0x/constexpr-ctor19.C: New test. Marek diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c index edade48..41665c5 100644 --- gcc/cp/constexpr.c +++ gcc/cp/constexpr.c @@ -425,7 +425,8 @@ check_constexpr_ctor_body_1 (tree last, tree list) switch (TREE_CODE (list)) { case DECL_EXPR: - if (TREE_CODE (DECL_EXPR_DECL (list)) == USING_DECL) + if (TREE_CODE (DECL_EXPR_DECL (list)) == USING_DECL + || TREE_CODE (DECL_EXPR_DECL (list)) == TYPE_DECL) return true; return false; diff --git gcc/testsuite/g++.dg/cpp0x/constexpr-ctor19.C gcc/testsuite/g++.dg/cpp0x/constexpr-ctor19.C index e69de29..f5ef053 100644 --- gcc/testsuite/g++.dg/cpp0x/constexpr-ctor19.C +++ gcc/testsuite/g++.dg/cpp0x/constexpr-ctor19.C @@ -0,0 +1,42 @@ +// PR c++/70229 +// { dg-do compile { target c++11 } } + +template +class S { + constexpr S (void) { + typedef int T; + } +}; + +template +class S2 { + constexpr S2 (void) { + ; + } +}; + +template +class S3 { + constexpr S3 (void) { + typedef enum { X } E; + } // { dg-error "does not have empty body" "" { target c++11_only } } +}; + +template +class S4 { + constexpr S4 (void) { + typedef struct { int j; } U; + } // { dg-error "does not have empty body" "" { target c++11_only } } +}; + +struct V +{ + int i; +}; + +template +class S5 { + constexpr S5 (void) { + typedef V W; + } +};