You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@stdcxx.apache.org by "Farid Zaripov (JIRA)" <ji...@apache.org> on 2009/08/04 15:55:14 UTC
[jira] Created: (STDCXX-1037) Bug in vector::swap() with unequal
allocators
Bug in vector::swap() with unequal allocators
---------------------------------------------
Key: STDCXX-1037
URL: https://issues.apache.org/jira/browse/STDCXX-1037
Project: C++ Standard Library
Issue Type: Bug
Components: 23. Containers
Affects Versions: 4.2.1, 4.2.0, 4.1.4, 4.1.3
Environment: All
Reporter: Farid Zaripov
Assignee: Farid Zaripov
Priority: Minor
Fix For: 4.2.2
The test below fails with assertion:
{noformat}
Assertion failed: 1 == v1.size() && 2 == v1.front(), file test.cpp, line 32
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
{noformat}
{code:title=test.cpp}
#include <cassert>
#include <memory>
#include <vector>
template <typename T>
class Alloc : public std::allocator<T>
{
public:
Alloc(int i) : i_(i) { }
int i_;
};
template <typename T>
bool operator==(const Alloc<T>& a1, const Alloc<T>& a2)
{
return a1.i_ == a2.i_;
}
int main ()
{
std::vector<int, Alloc<int> > v1(Alloc<int>(1));
v1.push_back(1);
assert(1 == v1.size() && 1 == v1.front());
std::vector<int, Alloc<int> > v2(Alloc<int>(2));
v2.push_back(2);
assert(1 == v2.size() && 2 == v2.front());
v1.swap(v2);
assert(1 == v1.size() && 2 == v1.front());
assert(1 == v2.size() && 1 == v2.front());
return 0;
}
{code}
The bug was introduced in [r355174|http://svn.apache.org/viewvc?view=rev&revision=355174]
The proposed patch:
{code:title=vector.cc.diff}
Index: vector.cc
===================================================================
--- vector.cc (revision 800774)
+++ vector.cc (working copy)
@@ -133,6 +133,7 @@
_RWSTD_ASSERT (__tmp.get_allocator () == __other.get_allocator ());
__tmp.assign (begin (), end ());
+ assign (__other.begin (), __other.end ());
__other.swap (__tmp);
}
{code}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (STDCXX-1037) Bug in vector::swap() with unequal
allocators
Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-1037?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12739079#action_12739079 ]
Martin Sebor commented on STDCXX-1037:
--------------------------------------
Yikes! That's a nasty bug! The patch looks good to me, but the test case isn't 100% right -- to be a valid allocator, class template {{Alloc}} must define all the same template members as the base, i.e., the template ctor, {{struct rebind}}, etc. Otherwise, for instance, {{Alloc<T>::rebind<U>::other}} wouldn't be the same as {{Alloc<U>}} (as the standard requires).
> Bug in vector::swap() with unequal allocators
> ---------------------------------------------
>
> Key: STDCXX-1037
> URL: https://issues.apache.org/jira/browse/STDCXX-1037
> Project: C++ Standard Library
> Issue Type: Bug
> Components: 23. Containers
> Affects Versions: 4.1.3, 4.1.4, 4.2.0, 4.2.1
> Environment: All
> Reporter: Farid Zaripov
> Assignee: Farid Zaripov
> Priority: Minor
> Fix For: 4.2.2
>
> Original Estimate: 1h
> Remaining Estimate: 1h
>
> The test below fails with assertion:
> {noformat}
> Assertion failed: 1 == v1.size() && 2 == v1.front(), file test.cpp, line 32
> This application has requested the Runtime to terminate it in an unusual way.
> Please contact the application's support team for more information.
> {noformat}
> {code:title=test.cpp}
> #include <cassert>
> #include <memory>
> #include <vector>
> template <typename T>
> class Alloc : public std::allocator<T>
> {
> public:
> Alloc(int i) : i_(i) { }
> int i_;
> };
> template <typename T>
> bool operator==(const Alloc<T>& a1, const Alloc<T>& a2)
> {
> return a1.i_ == a2.i_;
> }
> int main ()
> {
> std::vector<int, Alloc<int> > v1(Alloc<int>(1));
> v1.push_back(1);
> assert(1 == v1.size() && 1 == v1.front());
> std::vector<int, Alloc<int> > v2(Alloc<int>(2));
> v2.push_back(2);
> assert(1 == v2.size() && 2 == v2.front());
> v1.swap(v2);
> assert(1 == v1.size() && 2 == v1.front());
> assert(1 == v2.size() && 1 == v2.front());
> return 0;
> }
> {code}
> The bug was introduced in [r355174|http://svn.apache.org/viewvc?view=rev&revision=355174]
> The proposed patch:
> {code:title=vector.cc.diff}
> Index: vector.cc
> ===================================================================
> --- vector.cc (revision 800774)
> +++ vector.cc (working copy)
> @@ -133,6 +133,7 @@
> _RWSTD_ASSERT (__tmp.get_allocator () == __other.get_allocator ());
>
> __tmp.assign (begin (), end ());
> + assign (__other.begin (), __other.end ());
> __other.swap (__tmp);
> }
> {code}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (STDCXX-1037) Bug in vector::swap() with unequal
allocators
Posted by "Farid Zaripov (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-1037?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12743288#action_12743288 ]
Farid Zaripov commented on STDCXX-1037:
---------------------------------------
Merged to 4.3.x branch thus: http://svn.apache.org/viewvc?view=rev&revision=804290
Merged to trunk thus: http://svn.apache.org/viewvc?view=rev&revision=804291
> Bug in vector::swap() with unequal allocators
> ---------------------------------------------
>
> Key: STDCXX-1037
> URL: https://issues.apache.org/jira/browse/STDCXX-1037
> Project: C++ Standard Library
> Issue Type: Bug
> Components: 23. Containers
> Affects Versions: 4.1.3, 4.1.4, 4.2.0, 4.2.1
> Environment: All
> Reporter: Farid Zaripov
> Assignee: Farid Zaripov
> Priority: Minor
> Fix For: 4.2.2
>
> Original Estimate: 1h
> Time Spent: 1.02h
> Remaining Estimate: 0h
>
> The test below fails with assertion:
> {noformat}
> Assertion failed: 1 == v1.size() && 2 == v1.front(), file test.cpp, line 32
> This application has requested the Runtime to terminate it in an unusual way.
> Please contact the application's support team for more information.
> {noformat}
> {code:title=test.cpp}
> #include <cassert>
> #include <memory>
> #include <vector>
> template <typename T>
> class Alloc : public std::allocator<T>
> {
> public:
> Alloc(int i) : i_(i) { }
> int i_;
> };
> template <typename T>
> bool operator==(const Alloc<T>& a1, const Alloc<T>& a2)
> {
> return a1.i_ == a2.i_;
> }
> int main ()
> {
> std::vector<int, Alloc<int> > v1(Alloc<int>(1));
> v1.push_back(1);
> assert(1 == v1.size() && 1 == v1.front());
> std::vector<int, Alloc<int> > v2(Alloc<int>(2));
> v2.push_back(2);
> assert(1 == v2.size() && 2 == v2.front());
> v1.swap(v2);
> assert(1 == v1.size() && 2 == v1.front());
> assert(1 == v2.size() && 1 == v2.front());
> return 0;
> }
> {code}
> The bug was introduced in [r355174|http://svn.apache.org/viewvc?view=rev&revision=355174]
> The proposed patch:
> {code:title=vector.cc.diff}
> Index: vector.cc
> ===================================================================
> --- vector.cc (revision 800774)
> +++ vector.cc (working copy)
> @@ -133,6 +133,7 @@
> _RWSTD_ASSERT (__tmp.get_allocator () == __other.get_allocator ());
>
> __tmp.assign (begin (), end ());
> + assign (__other.begin (), __other.end ());
> __other.swap (__tmp);
> }
> {code}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (STDCXX-1037) Bug in vector::swap() with unequal
allocators
Posted by "Farid Zaripov (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-1037?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12743283#action_12743283 ]
Farid Zaripov commented on STDCXX-1037:
---------------------------------------
The regression test is added thus: http://svn.apache.org/viewvc?view=rev&revision=804283
> Bug in vector::swap() with unequal allocators
> ---------------------------------------------
>
> Key: STDCXX-1037
> URL: https://issues.apache.org/jira/browse/STDCXX-1037
> Project: C++ Standard Library
> Issue Type: Bug
> Components: 23. Containers
> Affects Versions: 4.1.3, 4.1.4, 4.2.0, 4.2.1
> Environment: All
> Reporter: Farid Zaripov
> Assignee: Farid Zaripov
> Priority: Minor
> Fix For: 4.2.2
>
> Original Estimate: 1h
> Remaining Estimate: 1h
>
> The test below fails with assertion:
> {noformat}
> Assertion failed: 1 == v1.size() && 2 == v1.front(), file test.cpp, line 32
> This application has requested the Runtime to terminate it in an unusual way.
> Please contact the application's support team for more information.
> {noformat}
> {code:title=test.cpp}
> #include <cassert>
> #include <memory>
> #include <vector>
> template <typename T>
> class Alloc : public std::allocator<T>
> {
> public:
> Alloc(int i) : i_(i) { }
> int i_;
> };
> template <typename T>
> bool operator==(const Alloc<T>& a1, const Alloc<T>& a2)
> {
> return a1.i_ == a2.i_;
> }
> int main ()
> {
> std::vector<int, Alloc<int> > v1(Alloc<int>(1));
> v1.push_back(1);
> assert(1 == v1.size() && 1 == v1.front());
> std::vector<int, Alloc<int> > v2(Alloc<int>(2));
> v2.push_back(2);
> assert(1 == v2.size() && 2 == v2.front());
> v1.swap(v2);
> assert(1 == v1.size() && 2 == v1.front());
> assert(1 == v2.size() && 1 == v2.front());
> return 0;
> }
> {code}
> The bug was introduced in [r355174|http://svn.apache.org/viewvc?view=rev&revision=355174]
> The proposed patch:
> {code:title=vector.cc.diff}
> Index: vector.cc
> ===================================================================
> --- vector.cc (revision 800774)
> +++ vector.cc (working copy)
> @@ -133,6 +133,7 @@
> _RWSTD_ASSERT (__tmp.get_allocator () == __other.get_allocator ());
>
> __tmp.assign (begin (), end ());
> + assign (__other.begin (), __other.end ());
> __other.swap (__tmp);
> }
> {code}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Resolved: (STDCXX-1037) Bug in vector::swap() with unequal
allocators
Posted by "Farid Zaripov (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-1037?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Farid Zaripov resolved STDCXX-1037.
-----------------------------------
Resolution: Fixed
Fixed thus: http://svn.apache.org/viewvc?view=rev&revision=804285
> Bug in vector::swap() with unequal allocators
> ---------------------------------------------
>
> Key: STDCXX-1037
> URL: https://issues.apache.org/jira/browse/STDCXX-1037
> Project: C++ Standard Library
> Issue Type: Bug
> Components: 23. Containers
> Affects Versions: 4.1.3, 4.1.4, 4.2.0, 4.2.1
> Environment: All
> Reporter: Farid Zaripov
> Assignee: Farid Zaripov
> Priority: Minor
> Fix For: 4.2.2
>
> Original Estimate: 1h
> Remaining Estimate: 1h
>
> The test below fails with assertion:
> {noformat}
> Assertion failed: 1 == v1.size() && 2 == v1.front(), file test.cpp, line 32
> This application has requested the Runtime to terminate it in an unusual way.
> Please contact the application's support team for more information.
> {noformat}
> {code:title=test.cpp}
> #include <cassert>
> #include <memory>
> #include <vector>
> template <typename T>
> class Alloc : public std::allocator<T>
> {
> public:
> Alloc(int i) : i_(i) { }
> int i_;
> };
> template <typename T>
> bool operator==(const Alloc<T>& a1, const Alloc<T>& a2)
> {
> return a1.i_ == a2.i_;
> }
> int main ()
> {
> std::vector<int, Alloc<int> > v1(Alloc<int>(1));
> v1.push_back(1);
> assert(1 == v1.size() && 1 == v1.front());
> std::vector<int, Alloc<int> > v2(Alloc<int>(2));
> v2.push_back(2);
> assert(1 == v2.size() && 2 == v2.front());
> v1.swap(v2);
> assert(1 == v1.size() && 2 == v1.front());
> assert(1 == v2.size() && 1 == v2.front());
> return 0;
> }
> {code}
> The bug was introduced in [r355174|http://svn.apache.org/viewvc?view=rev&revision=355174]
> The proposed patch:
> {code:title=vector.cc.diff}
> Index: vector.cc
> ===================================================================
> --- vector.cc (revision 800774)
> +++ vector.cc (working copy)
> @@ -133,6 +133,7 @@
> _RWSTD_ASSERT (__tmp.get_allocator () == __other.get_allocator ());
>
> __tmp.assign (begin (), end ());
> + assign (__other.begin (), __other.end ());
> __other.swap (__tmp);
> }
> {code}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.