Skip to content

Cleanup: Fix warning about binding to a temporary in range-based for

This is intended to fix a warning that started appearing a couple of weeks ago in one of the nightly builds, reproduced here for traceability:

/home/buildbot/repos/CMake/Source/cmLocalGenerator.cxx: In member function 'void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget*)':
[CTest: warning matched] /home/buildbot/repos/CMake/Source/cmLocalGenerator.cxx:2478:29: warning: loop variable 'lang' of type 'const string&' {aka 'const std::__cxx11::basic_string<char>&'} binds to a temporary constructed from type 'const char* const' [-Wrange-loop-construct]
 2478 |     for (const std::string& lang : { "C", "CXX", "OBJC", "OBJCXX" }) {
      |                             ^~~~
[CTest: warning matched] /home/buildbot/repos/CMake/Source/cmLocalGenerator.cxx:2478:29: note: use non-reference type 'const string' {aka 'const std::__cxx11::basic_string<char>'} to make the copy explicit or 'const char* const&' to prevent copying

Cc: @cristianadam

Merge request reports