This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Protect from comma operator overload
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: François Dumont <frs dot dumont at gmail dot com>
- Cc: "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 16 Apr 2018 21:16:58 +0100
- Subject: Re: Protect from comma operator overload
- References: <e21ee73e-fa91-2c95-2c0e-8648b299216b@gmail.com> <CAH6eHdTsvXOFyU_855toTcpR+gjg0KZXXeDH5=GQJumRQTfSVQ@mail.gmail.com>
On 16 April 2018 at 21:08, Jonathan Wakely wrote:
> On 16 April 2018 at 20:52, François Dumont wrote:
>> Hi
>>
>> While working on something else on libstdc++ I started having a test
>> failing because of the missing comma overload protection in deque.tcc. So I
>> looked for other similar places in the code and here is a patch to fix the
>> places I found.
>>
>> Let me know if it is still time to commit.
>
> The changes look right, but please add new tests to demonstrate the
> code that used to fail.
>
> You can use <testsuite_iterators.h> because the iterator types defined
> in there have deleted comma operators that should cause errors in
> these places.
Something like this (but in four separate tests):
#include <deque>
#include <list>
#include <vector>
#include <testsuite_iterators.h>
int main()
{
using namespace __gnu_test;
int a[1] = {};
test_container<int, input_iterator_wrapper> t(a, a+1);
std::deque<int> d;
d.assign(t.begin(), t.end());
std::list<int> l;
l.assign(t.begin(), t.end());
std::vector<int> v;
v.assign(t.begin(), t.end());
std::vector<bool> b;
b.assign(t.begin(), t.end());
}
Given how rare it is for real code to overload the comma operator, and
that nobody has reported these bugs, I think this can wait for after
GCC 8.