From patchwork Thu Jun 14 22:07:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 165022 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 243B2B700A for ; Fri, 15 Jun 2012 08:08:17 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1340316498; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received:Date:Message-ID:Subject:From:To: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=HJcag+I NJ4mDc70qBMTI/bEJwBM=; b=OfbIqLm++XXvF2vP7AsXliHPICp6o35v/T6gdH2 dtQEpws1+DQ2KPAiGxGLEr4DlfdCxerCYCMJn4QKfeAYl5kolScAIdnjhWwS3DLH 7JLHO7XEUJnawqSQzG5x8iXOPP1izTE7mINPlogRiONtmropzmMtdiS9SsN30pYO IqsA= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:MIME-Version:Received:Received:Date:Message-ID:Subject:From:To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=W7K8foETIahySkblqVXKgiproMtyLOqmGuai+UmxG0tvOimnQdEGkKdjNG0xJI it563ddKrVTXw3OlCiSDUTdWw0DeoU1Pmj7kglEEUrFBkOhDVdpkRT5tntWCkqMt fnXIPPM8HyvluEU2w8STSbtjg+k6OnR9fDcS8XLcIB3qo=; Received: (qmail 797 invoked by alias); 14 Jun 2012 22:08:06 -0000 Received: (qmail 771 invoked by uid 22791); 14 Jun 2012 22:08:05 -0000 X-SWARE-Spam-Status: No, hits=-4.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-lpp01m010-f47.google.com (HELO mail-lpp01m010-f47.google.com) (209.85.215.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 14 Jun 2012 22:07:46 +0000 Received: by lags15 with SMTP id s15so1719659lag.20 for ; Thu, 14 Jun 2012 15:07:44 -0700 (PDT) MIME-Version: 1.0 Received: by 10.152.123.244 with SMTP id md20mr3444245lab.0.1339711664398; Thu, 14 Jun 2012 15:07:44 -0700 (PDT) Received: by 10.112.48.6 with HTTP; Thu, 14 Jun 2012 15:07:44 -0700 (PDT) Date: Thu, 14 Jun 2012 23:07:44 +0100 Message-ID: Subject: [v3] fix PR 53648 From: Jonathan Wakely To: "libstdc++" , gcc-patches 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 Using the empty base-class optimization in std::tuple can result in ambiguous base classes when you have a tuple of tuples. This patch disables the EBO for tuple elements that are themselves tuples, with tuple_size > 1 (because for a zero-size tuple the base class will be _Tuple_impl<1> and the tuple that contains it must have _Tuple_impl where N>1, because it contains at least one element, the zero-sized tuple). PR libstdc++/53648 * include/std/tuple (__empty_not_final): Do not use EBO for tuples. * testsuite/20_util/tuple/53648.cc: New. * testsuite/20_util/uses_allocator/cons_neg.cc: Adjust dg-error line number. Tested x86_64-linux, committed to trunk. Although I think it would be safe I have no plans to apply it to release branches. commit b069e0d58ce0c4d54d67aa5c85e88022a317817a Author: Jonathan Wakely Date: Thu Jun 14 22:02:26 2012 +0100 PR libstdc++/53648 * include/std/tuple (__empty_not_final): Do not use EBO for tuples. * testsuite/20_util/tuple/53648.cc: New. * testsuite/20_util/uses_allocator/cons_neg.cc: Adjust dg-error line number. diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index 4d4691f..fb9e09f 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -1,6 +1,7 @@ // -*- C++ -*- -// Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. +// Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 +// Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -201,10 +202,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION void _M_swap(_Tuple_impl&) noexcept { /* no-op */ } }; + template + struct __is_empty_non_tuple : is_empty<_Tp> { }; + + // Using EBO for elements that are tuples causes ambiguous base errors. + template + struct __is_empty_non_tuple> : false_type { }; + // Use the Empty Base-class Optimization for empty, non-final types. template using __empty_not_final - = typename conditional<__is_final(_Tp), false_type, is_empty<_Tp>>::type; + = typename conditional<__is_final(_Tp), false_type, + __is_empty_non_tuple<_Tp>>::type; /** * Recursive tuple implementation. Here we store the @c Head element diff --git a/libstdc++-v3/testsuite/20_util/tuple/53648.cc b/libstdc++-v3/testsuite/20_util/tuple/53648.cc new file mode 100644 index 0000000..5671e44 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/53648.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2012 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// libstdc++/53648 + +#include +#include + +using std::tuple; + +struct A { }; + +template class tuple>; +template class tuple>>; +template class tuple>>>; +template class tuple, A>, A>; + +// Verify the following QoI properties are preserved + +static_assert( std::is_empty>::value, "tuple<> is empty" ); + +static_assert( std::is_empty>>::value, + "tuple> is empty" ); + +static_assert( sizeof(tuple>) == sizeof(char), + "tuple<> is eligible for EBO" ); + diff --git a/libstdc++-v3/testsuite/20_util/uses_allocator/cons_neg.cc b/libstdc++-v3/testsuite/20_util/uses_allocator/cons_neg.cc index 73a0d0f..d81dd35 100644 --- a/libstdc++-v3/testsuite/20_util/uses_allocator/cons_neg.cc +++ b/libstdc++-v3/testsuite/20_util/uses_allocator/cons_neg.cc @@ -44,4 +44,4 @@ void test01() tuple t(allocator_arg, a, 1); } -// { dg-error "no matching function" "" { target *-*-* } 112 } +// { dg-error "no matching function" "" { target *-*-* } 113 }