From patchwork Wed Feb 16 16:28:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 83375 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]) by ozlabs.org (Postfix) with SMTP id 989E3B70E4 for ; Thu, 17 Feb 2011 03:28:34 +1100 (EST) Received: (qmail 11671 invoked by alias); 16 Feb 2011 16:28:32 -0000 Received: (qmail 11658 invoked by uid 22791); 16 Feb 2011 16:28:31 -0000 X-SWARE-Spam-Status: No, hits=-5.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 16 Feb 2011 16:28:25 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p1GGSNI8022603 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 16 Feb 2011 11:28:23 -0500 Received: from adjoa.redhat.com (ovpn-113-49.phx2.redhat.com [10.3.113.49]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p1GGSLeP003965; Wed, 16 Feb 2011 11:28:22 -0500 From: Dodji Seketeli To: Jason Merrill Cc: GCC Patches Subject: [PATCH] PR c++/47326 X-URL: http://www.redhat.com Date: Wed, 16 Feb 2011 17:28:20 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes 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 Hello, Consider this example: template struct A { typedef int value_type; }; template auto f (_ARGS... args) -> typename A::value_type { return 12; } int main() { f(1,2); } Near the end of unification of f(1,2), we substitute the unified types into the return type of f and we fail to ensure that the argument [when it is a pack expansion] of sizeof is not evaluated. Tested on x86_64-unknown-linux-gnu against trunk. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index d59f32a..64eb027 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -11380,11 +11380,18 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) case SIZEOF_EXPR: if (PACK_EXPANSION_P (TREE_OPERAND (t, 0))) { - /* We only want to compute the number of arguments. */ - tree expanded = tsubst_pack_expansion (TREE_OPERAND (t, 0), args, - complain, in_decl); + + tree expanded; int len = 0; + ++cp_unevaluated_operand; + ++c_inhibit_evaluation_warnings; + /* We only want to compute the number of arguments. */ + expanded = tsubst_pack_expansion (TREE_OPERAND (t, 0), args, + complain, in_decl); + --cp_unevaluated_operand; + --c_inhibit_evaluation_warnings; + if (TREE_CODE (expanded) == TREE_VEC) len = TREE_VEC_LENGTH (expanded); diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic106.C b/gcc/testsuite/g++.dg/cpp0x/variadic106.C new file mode 100644 index 0000000..80ec084 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/variadic106.C @@ -0,0 +1,22 @@ +// Origin: PR c++/47326 +// { dg-options "-std=c++0x" } +// { dg-do compile } + +template +struct A +{ + typedef int value_type; +}; + +template +auto +f (_ARGS... args) -> typename A::value_type +{ + return 12; +} + +int +main() +{ + f(1,2); +}