From: Jonathan Wakely Date: Mon, 18 Feb 2013 22:51:23 +0000 (+0000) Subject: functional (mem_fn): Qualify to prevent ADL. X-Git-Tag: releases/gcc-4.7.3~185 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4b662153f44b349f96a1d2331f5f047ace306548;p=thirdparty%2Fgcc.git functional (mem_fn): Qualify to prevent ADL. * include/std/functional (mem_fn): Qualify to prevent ADL. * testsuite/20_util/function_objects/mem_fn/adl.cc: New. From-SVN: r196128 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6ee913272f8b..96e68e45d688 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,8 @@ +2013-02-18 Jonathan Wakely + + * include/std/functional (mem_fn): Qualify to prevent ADL. + * testsuite/20_util/function_objects/mem_fn/adl.cc: New. + 2013-02-18 Jonathan Wakely * include/bits/hashtable.h: Improve comments. diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index 782400b39c6b..e2cdd65f4c1c 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -1,7 +1,7 @@ // -*- C++ -*- // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, -// 2011, 2012 Free Software Foundation, Inc. +// 2011, 2012, 2013 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 @@ -245,7 +245,7 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) >::type __invoke(_Functor& __f, _Args&&... __args) { - return mem_fn(__f)(std::forward<_Args>(__args)...); + return std::mem_fn(__f)(std::forward<_Args>(__args)...); } // To pick up function references (that will become function pointers) @@ -1709,12 +1709,12 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) template inline _Mem_fn<_Member _Class::*> __callable_functor(_Member _Class::* &__p) - { return mem_fn(__p); } + { return std::mem_fn(__p); } template inline _Mem_fn<_Member _Class::*> __callable_functor(_Member _Class::* const &__p) - { return mem_fn(__p); } + { return std::mem_fn(__p); } template class function; @@ -1969,7 +1969,7 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) static _Res _M_invoke(const _Any_data& __functor, _ArgTypes... __args) { - return mem_fn(_Base::_M_get_pointer(__functor)->__value)( + return std::mem_fn(_Base::_M_get_pointer(__functor)->__value)( std::forward<_ArgTypes>(__args)...); } }; @@ -2009,7 +2009,7 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type) static void _M_invoke(const _Any_data& __functor, _ArgTypes... __args) { - mem_fn(_Base::_M_get_pointer(__functor)->__value)( + std::mem_fn(_Base::_M_get_pointer(__functor)->__value)( std::forward<_ArgTypes>(__args)...); } }; diff --git a/libstdc++-v3/testsuite/20_util/function_objects/mem_fn/adl.cc b/libstdc++-v3/testsuite/20_util/function_objects/mem_fn/adl.cc new file mode 100644 index 000000000000..cd7d0864f3f7 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/function_objects/mem_fn/adl.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 2012-2013 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 +// . + +#include + +namespace n { + struct X { int i; }; + void mem_fn(int X::*); +} + +using n::X; + +X x{}; +int X::* p = &X::i; + +int test01() +{ + auto ref = std::ref(p); + return ref(x); +} + +int test02() +{ + std::function fun(p); + return fun(x); +} +