User account creation filtered due to spam.

Bug 48541 - std::function(std::_Function_base) should use std::addressof
Summary: std::function(std::_Function_base) should use std::addressof
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.1
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2011-04-10 13:43 UTC by Norihisa Fujita
Modified: 2011-04-11 18:32 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-04-10 13:58:50


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Norihisa Fujita 2011-04-10 13:43:32 UTC
In std::_Function_base::_M_get_pointer, operator & is used to get a pointer of the functor.
So, some callable objects which override operator & and they don't return their pointer couldn't be held by std::function.

----
struct X {
  void operator ()() const {
    std::cerr << "X()\n";
  }
  float operator &() const {
    return 1.2345;
  }
};
int main() {
  X x;
  std::function<void ()> f(x);
  return 0;
}
----
Comment 1 Jonathan Wakely 2011-04-10 16:29:09 UTC
Author: redi
Date: Sun Apr 10 16:29:05 2011
New Revision: 172242

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172242
Log:
2011-04-10  Jonathan Wakely  <jwakely.gcc@gmail.com>

	PR libstdc++/48541
	* include/std/functional (_Base_manager::_M_get_pointer): Use
	addressof.
	* testsuite/20_util/function/48541.cc: New.


Added:
    branches/gcc-4_6-branch/libstdc++-v3/testsuite/20_util/function/48451.cc
Modified:
    branches/gcc-4_6-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_6-branch/libstdc++-v3/include/std/functional
Comment 2 Jonathan Wakely 2011-04-10 16:36:01 UTC
Author: redi
Date: Sun Apr 10 16:35:58 2011
New Revision: 172244

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172244
Log:
2011-04-10  Jonathan Wakely  <jwakely.gcc@gmail.com>

	PR libstdc++/48541
	* include/std/functional (_Base_manager::_M_get_pointer): Use
	addressof.
	* testsuite/20_util/function/48541.cc: New.


Added:
    trunk/libstdc++-v3/testsuite/20_util/function/48541.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/std/functional
Comment 3 Jonathan Wakely 2011-04-10 16:36:57 UTC
fixed for 4.6.1 - thanks for the report
Comment 4 Paolo Carlini 2011-04-11 18:32:12 UTC
Thanks Jon.