[Bug c++/105470] ranged for loop whitespace parsing

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed May 4 00:18:24 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105470

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|---                         |INVALID

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Roland Hughes from comment #0)
> If you look at the error message, this version of the compiler demands the &
> be against > instead of out with the variable.

No it doesn't.

> This appears to be a whitespace parsing bug.

I don't think so.

The warning is completely correct, and the code should be fixed.

for ( const std::pair<KeyModifiers, Scintilla::Message> &it : someMap )

This iterates over a map, with values of type:

std::pair<const KeyModifiers, Scintilla::Message>

But the loop is using a reference to a different type:

std::pair<KeyModifiers, Scintilla::Message>

That causes a temporary to be created on every iteration of the loop, and the
const-refernece binds to the temporary. The new GCC is smart enough to tell you
this, and you've asked for that warning to be a fatal error.

Either don't enable errors for that warning, or fix the code to avoid the
unnecessary temporaries being created.


More information about the Gcc-bugs mailing list