abumq / easyloggingpp

C++ logging library. It is extremely powerful, extendable, light-weight, fast performing, thread and type safe and consists of many built-in features. It provides ability to write logs in your own customized format. It also provide support for logging your classes, third-party libraries, STL and third-party containers etc.
MIT License
3.75k stars 918 forks source link

Please fix compiler warnings #845

Open jagiella opened 10 months ago

jagiella commented 10 months ago

Compiling with g++ I get the following compiler warnings:

/usr/include/easylogging++.cc: In member function ‘el::Logger* el::base::RegisteredLoggers::get(const std::string&, bool)’:
/usr/include/easylogging++.cc:1900:83: warning: loop variable ‘h’ of type ‘const std::pair<std::__cxx11::basic_string<char>, std::shared_ptr<el::LoggerRegistrationCallback> >&’ binds to a temporary constructed from type ‘std::pair<const std::__cxx11::basic_string<char>, std::shared_ptr<el::LoggerRegistrationCallback> >’ [-Wrange-loop-construct]
 1900 |     for (const std::pair<std::string, base::type::LoggerRegistrationCallbackPtr>& h
      |                                                                                   ^
/usr/include/easylogging++.cc:1900:83: note: use non-reference type ‘const std::pair<std::__cxx11::basic_string<char>, std::shared_ptr<el::LoggerRegistrationCallback> >’ to make the copy explicit or ‘const std::pair<const std::__cxx11::basic_string<char>, std::shared_ptr<el::LoggerRegistrationCallback> >&’ to prevent copying
/usr/include/easylogging++.cc: In member function ‘void el::base::LogDispatcher::dispatch()’:
/usr/include/easylogging++.cc:2492:74: warning: loop variable ‘h’ of type ‘const std::pair<std::__cxx11::basic_string<char>, std::shared_ptr<el::LogDispatchCallback> >&’ binds to a temporary constructed from type ‘std::pair<const std::__cxx11::basic_string<char>, std::shared_ptr<el::LogDispatchCallback> >’ [-Wrange-loop-construct]
 2492 |   for (const std::pair<std::string, base::type::LogDispatchCallbackPtr>& h
      |                                                                          ^
/usr/include/easylogging++.cc:2492:74: note: use non-reference type ‘const std::pair<std::__cxx11::basic_string<char>, std::shared_ptr<el::LogDispatchCallback> >’ to make the copy explicit or ‘const std::pair<const std::__cxx11::basic_string<char>, std::shared_ptr<el::LogDispatchCallback> >&’ to prevent copying

Of the two proposed solutions it would certainly make sense to change the impacted two lines as following:

$ g++ --version
g++ (Ubuntu 13.2.0-4ubuntu3) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.