diff options
| author | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-01-27 15:49:00 +0000 |
|---|---|---|
| committer | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-01-27 15:49:00 +0000 |
| commit | 9165991ed7b8737dc22b087b2fea8cff17ebff30 (patch) | |
| tree | 41da2c42473b85d27731c803582dd08dd982c329 /libstdc++-v3/include/tr1/functional | |
| parent | 5711f254674a9220f03d0616504e6c22d0ca6f41 (diff) | |
| download | ppe42-gcc-9165991ed7b8737dc22b087b2fea8cff17ebff30.tar.gz ppe42-gcc-9165991ed7b8737dc22b087b2fea8cff17ebff30.zip | |
2010-01-27 Richard Guenther <rguenther@suse.de>
PR libstdc++/42832
* include/std/functional (function<>::swap): Perform bytewise
swap of _M_functor.
* include/tr1/functional (function<>::swap): Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@156290 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/tr1/functional')
| -rw-r--r-- | libstdc++-v3/include/tr1/functional | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/libstdc++-v3/include/tr1/functional b/libstdc++-v3/include/tr1/functional index 4825509aed7..2052f885de8 100644 --- a/libstdc++-v3/include/tr1/functional +++ b/libstdc++-v3/include/tr1/functional @@ -1904,9 +1904,16 @@ namespace tr1 */ void swap(function& __x) { - _Any_data __old_functor = _M_functor; - _M_functor = __x._M_functor; - __x._M_functor = __old_functor; + /* We cannot perform direct assignments of the _M_functor + parts as they are of type _Any_data and have a different + dynamic type. Doing so would violate type-based aliasing + rules and lead to spurious miscompilations. + Instead perform a bytewise exchange of the memory of + both POD objects. + ??? A wordwise exchange honoring alignment of _M_functor + would be more efficient. See PR42845. */ + for (unsigned i = 0; i < sizeof (_M_functor._M_pod_data); ++i) + std::swap (_M_functor._M_pod_data[i], __x._M_functor._M_pod_data[i]); _Manager_type __old_manager = _M_manager; _M_manager = __x._M_manager; __x._M_manager = __old_manager; |

