Re: [PATCH 3/3] gdb/objfiles: use filtered_iterator as objfile::section_iterator

Simon Marchi
2025-08-29T16:07:15Z

On 2025-08-29 09:42, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:
>
> Simon> objfile::section_iterator looks like a good candidate to be implemented
> Simon> with filtered_iterator. Following the enhancements to filtered_iterator
> Simon> in the previous patch, it's pretty straighforward.
>
> Simon> I removed the non-const version of objfile::sections, because it didn't
> Simon> seem useful to have the two methods returning the exact same type and
> Simon> value. Having just the const version achieves the same thing.
>
> I would have thought the const one would return a const iterator and not
> allow modifications to the underlying objects.

I don't think it did that, because section_iterator specifically used
a non-const `obj_section *` as the value type.

I can see it easily with clangd in VSCode. With this function:

void test ()
{
decltype(auto) nc = *static_cast<objfile *> (nullptr)->sections ().begin ();
decltype(auto) c = *static_cast<const objfile *> (nullptr)->sections ().begin ();
}

... when I hover `decltype(auto)` in both cases, it says the deduced
type is `obj_section &` (non-const). It was `obj_section *` in both
cases before my patch that make the iterator yield references.

> Anyway if it didn't then that's just some pre-existing bug, probably not
> too important.

I'll see if I can make it right, while at it, but otherwise I don't
think it's a big deal. Not that it's good, but it's not like we are
anywhere near to have const-correctness in GDB (yet).

Simon