Uploaded image for project: 'Log4cxx'
  1. Log4cxx
  2. LOGCXX-150

logstream's operator<< declared in the wrong namespace

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 0.10.0
    • 0.10.0
    • None
    • None
    • FC4 - g++ (GCC) 4.0.2 20051125

    Description

      This is one of those strange nuances of C++ (or maybe just GCC). logstream's << operators don't work from within a namespace that has operator<< defined. For example:

      #include <log4cxx/logger.h>
      #include <log4cxx/stream.h>
      #include <ostream>

      namespace foo
      {
      class Bar

      { void fn(); }

      ;

      std::ostream &operator<<(std::ostream &o, Bar const &b)

      { return o << "Bar"; }

      }

      using namespace foo;

      namespace
      {
      log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("foo"));
      log4cxx::logstream lout(logger, log4cxx::Level::DEBUG);
      }

      void Bar::fn()
      {
      lout << "hi" << LOG4CXX_ENDMSG;
      }

      Compiles with the following error:
      g++ -c -o log4cxx-ns.o log4cxx-ns.cpp
      log4cxx-ns.cpp: In member function 'void foo::Bar::fn()':
      log4cxx-ns.cpp:29: error: no match for 'operator<<' in '<unnamed>::lout << "hi"'
      log4cxx-ns.cpp:12: note: candidates are: std::ostream& foo::operator<<(std::ostream&, const foo::Bar&)

      For the Koenig lookup to work properly, the operator<< functions need to be defined in the log4cxx namespace.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            carnold@apache.org Curt Arnold
            dmlee@crossroads.com David M. Lee
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment