Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please fix compiler warnings #845

Open
jagiella opened this issue Oct 30, 2023 · 0 comments
Open

Please fix compiler warnings #845

jagiella opened this issue Oct 30, 2023 · 0 comments

Comments

@jagiella
Copy link

jagiella commented Oct 30, 2023

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant