This is the mail archive of the
mailing list for the GCC project.
Re: Possible range based 'for' bug
- From: Julian Klappenbach <jklappenbach at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Sun, 21 Jun 2015 11:16:16 -0700
- Subject: Re: Possible range based 'for' bug
- Authentication-results: sourceware.org; auth=none
- References: <CAJ49vaUdYycmCPFEhCmJ9uSAzj2pCdp8oRC=yx1NSG1yZgNExA at mail dot gmail dot com> <CAJ49vaVYqrGCxh46riYjiZea-9vXNzBfTHqwUPi6NPsvzQ-Ftg at mail dot gmail dot com> <CAH6eHdSiONCF8LCtuasaQhGmW8Drq5fDZ6sDgYUVNWCnFi4xMw at mail dot gmail dot com>
The issue occurred to me after I sent the email.
begin() / end() return iterators by value, not reference.
So, you're correct in identifying the value / reference issue. But to
be precise: you can't return an abstract class type *by value* from a
function. If the return values of begin() / end() were returned and
accepted as a reference, then I believe this would work. This
difference is that return by value results in an implicit
instantiation, which would attempt to create the
Given that the existing libs all are coded to return iterators by
value from begin() / end(), I would assume that converting the
range-for logic to work with references would cause some nasty
On Sun, Jun 21, 2015 at 10:49 AM, Jonathan Wakely <firstname.lastname@example.org> wrote:
> On 21 June 2015 at 16:56, Julian Klappenbach wrote:
>> Version info:
>> Configured with:
>> Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
>> Target: x86_64-apple-darwin14.3.0
>> Thread model: posix
> You're not using GCC, you're using LLVM.
> Even if you were using GCC "is this a bug?" questions are off-topic on
> this list, they belong in the Bugzilla bug tracker or the gcc-help
> mailing list, not here.
>> Since I have many different types of iterators, I had created a basic
>> interface to pass them around, an abstract virtual class with pure
>> virtual members. The problem occurs when the logic behind the range
>> based for loop calls begin, and receives the pure virtual base class
>> of the iterator. This causes the compiler error:
>> ../src/ListTests.cpp:156:13: error: variable type 'Iterable<int>' is
>> an abstract class
> It sounds like your begin() function is declared to return an abstract
> class by value, that is not possible in C++. THis has nothign to do
> with range-based for, you just can't return an abstract class type
> from a function.