Please fix compiler warnings
jagiella opened this issue · comments
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:
- line 1900:
- for (const std::pair<std::string, base::type::LoggerRegistrationCallbackPtr>& h
+ for (const std::pair<const std::string, base::type::LoggerRegistrationCallbackPtr>& h
: m_loggerRegistrationCallbacks) {
callback = h.second.get();
if (callback != nullptr && callback->enabled()) {
callback->handle(logger_);
}
}
- line 2492:
- for (const std::pair<std::string, base::type::LogDispatchCallbackPtr>& h
+ for (const std::pair<const std::string, base::type::LogDispatchCallbackPtr>& h
: ELPP->m_logDispatchCallbacks) {
callback = h.second.get();
if (callback != nullptr && callback->enabled()) {
data.setLogMessage(m_logMessage);
data.setDispatchAction(m_dispatchAction);
callback->handle(&data);
}
}
$ 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.