[Bug c++/105470] ranged for loop whitespace parsing
roland at logikalsolutions dot com
gcc-bugzilla@gcc.gnu.org
Wed May 4 14:40:39 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105470
--- Comment #10 from Roland Hughes <roland at logikalsolutions dot com> ---
(In reply to Marek Polacek from comment #1)
>
> 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>
>
No, it doesn't.
[code]
roland@roland-HP-EliteDesk-800-G2-SFF:~/sf_projects/roland_hughes-csscintilla$
grep -irn GetKeyMap *
copperspice/CsScintillaEditBase/CsScintillaEditBase.cpp:1031: // the fact
GetKeyMap() returns const means we can't use an iterator
copperspice/CsScintillaEditBase/CsScintillaEditBase.cpp:1034: for ( const
std::pair<KeyModifiers, Scintilla::Message> &it : sqt->kmap.GetKeyMap() )
copperspice/CsScintillaEditBase/CsScintillaEditBase.cpp:1059: auto
findResult = std::find_if( std::begin( sqt->kmap.GetKeyMap() ),
copperspice/CsScintillaEditBase/CsScintillaEditBase.cpp:1060:
std::end( sqt->kmap.GetKeyMap() ),
copperspice/CsScintillaEditBase/CsScintillaEditBase.cpp:1066: if (
findResult != std::end( sqt->kmap.GetKeyMap() ) )
copperspice/CsScintillaEditBase/CsScintillaEditBase.cpp:4314:const
std::map<Scintilla::Internal::KeyModifiers, Scintilla::Message>
&CsScintillaEditBase::GetKeyMap() const noexcept
copperspice/CsScintillaEditBase/CsScintillaEditBase.cpp:4316: return
sqt->kmap.GetKeyMap();
copperspice/CsScintillaEditBase/CsScintillaEditBase.h:79: const
std::map<Scintilla::Internal::KeyModifiers, Scintilla::Message> &GetKeyMap()
const noexcept;
src/KeyMap.h:60: const std::map<KeyModifiers, Scintilla::Message>
&GetKeyMap() const noexcept;
src/KeyMap.cxx:50:const std::map<KeyModifiers, Message> &KeyMap::GetKeyMap()
const noexcept {
[/code]
There is no definition of that map anywhere in the codebase where KeyModifiers
is declared const.
The method being called returns a const & to the entire map, but there is no
const declared within the map.
More information about the Gcc-bugs
mailing list