From patchwork Sun Apr 10 16:36:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 90524 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 80AD3B6F2B for ; Mon, 11 Apr 2011 02:36:17 +1000 (EST) Received: (qmail 11774 invoked by alias); 10 Apr 2011 16:36:14 -0000 Received: (qmail 11588 invoked by uid 22791); 10 Apr 2011 16:36:12 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-pw0-f47.google.com (HELO mail-pw0-f47.google.com) (209.85.160.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 10 Apr 2011 16:36:08 +0000 Received: by pwj9 with SMTP id 9so2840956pwj.20 for ; Sun, 10 Apr 2011 09:36:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.142.172.20 with SMTP id u20mr4385171wfe.14.1302453367707; Sun, 10 Apr 2011 09:36:07 -0700 (PDT) Received: by 10.143.10.15 with HTTP; Sun, 10 Apr 2011 09:36:07 -0700 (PDT) Date: Sun, 10 Apr 2011 17:36:07 +0100 Message-ID: Subject: fix libstdc++/48541 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 A simple one. PR libstdc++/48541 * include/std/functional (_Base_manager::_M_get_pointer): Use addressof. * testsuite/20_util/function/48541.cc: New. Tested x86_64-linux, committed to trunk and the 4.6 branch. Index: include/std/functional =================================================================== --- include/std/functional (revision 172239) +++ include/std/functional (working copy) @@ -1586,7 +1586,7 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) _M_get_pointer(const _Any_data& __source) { const _Functor* __ptr = - __stored_locally? &__source._M_access<_Functor>() + __stored_locally? std::__addressof(__source._M_access<_Functor>()) /* have stored a pointer */ : __source._M_access<_Functor*>(); return const_cast<_Functor*>(__ptr); } Index: testsuite/20_util/function/48451.cc =================================================================== --- testsuite/20_util/function/48451.cc (revision 0) +++ testsuite/20_util/function/48451.cc (revision 0) @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } +// Copyright (C) 2011 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++/48451 + +#include + +struct X { + void operator () () const { } + float operator & () const { return 1.2345; } +}; + +void test01() +{ + X x; + std::function f(x); + f(); +} + +int main() +{ + test01(); + return 0; +}