Author: carnold
Date: Thu Nov  8 12:07:09 2007
New Revision: 593286

URL: http://svn.apache.org/viewvc?rev=593286&view=rev
Log:
LOGCXX-150: logstream's operator<< declared in wrong namespace

Modified:
    logging/log4cxx/trunk/src/main/include/log4cxx/log4cxx.hw
    logging/log4cxx/trunk/src/main/include/log4cxx/stream.h
    logging/log4cxx/trunk/src/test/cpp/streamtestcase.cpp

Modified: logging/log4cxx/trunk/src/main/include/log4cxx/log4cxx.hw
URL: 
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/log4cxx.hw?rev=593286&r1=593285&r2=593286&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/include/log4cxx/log4cxx.hw (original)
+++ logging/log4cxx/trunk/src/main/include/log4cxx/log4cxx.hw Thu Nov  8 
12:07:09 2007
@@ -35,6 +35,9 @@
 
 #if defined(_MSC_VER)
 typedef __int64 log4cxx_int64_t;
+#if _MSC_VER < 1300
+#define LOG4CXX_USE_GLOBAL_SCOPE_TEMPLATE 1
+#endif
 #else
 typedef long long log4cxx_int64_t;
 #endif

Modified: logging/log4cxx/trunk/src/main/include/log4cxx/stream.h
URL: 
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/stream.h?rev=593286&r1=593285&r2=593286&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/include/log4cxx/stream.h (original)
+++ logging/log4cxx/trunk/src/main/include/log4cxx/stream.h Thu Nov  8 12:07:09 
2007
@@ -263,6 +263,21 @@
              *   Cast operator to provide access to embedded 
std::basic_ostream.
              */
              operator std::basic_ostream<Ch>&();
+
+#if !(LOG4CXX_USE_GLOBAL_SCOPE_TEMPLATE)             
+            /**
+              *  Template to allow any class with an std::basic_ostream 
inserter
+              *    to be applied to this class.
+             */
+             template <class V>
+             inline log4cxx::logstream& operator<<(const V& val) {
+                 if (LOG4CXX_UNLIKELY(isEnabled())) {
+                      ((std::basic_ostream<char>&) *this) << val;
+                 }
+                 return *this;
+              }
+#endif              
+             
             
         protected:
               /**
@@ -359,6 +374,20 @@
              */
              operator std::basic_ostream<Ch>&();
             
+#if !(LOG4CXX_USE_GLOBAL_SCOPE_TEMPLATE)             
+            /**
+              *  Template to allow any class with an std::basic_ostream 
inserter
+              *    to be applied to this class.
+             */
+             template <class V>
+             inline log4cxx::wlogstream& operator<<(const V& val) {
+                 if (LOG4CXX_UNLIKELY(isEnabled())) {
+                      ((std::basic_ostream<wchar_t>&) *this) << val;
+                 }
+                 return *this;
+              }
+#endif              
+            
         protected:
               /**
                *   [EMAIL PROTECTED]
@@ -395,6 +424,13 @@
 }  // namespace log4cxx
 
 
+#if LOG4CXX_USE_GLOBAL_SCOPE_TEMPLATE
+//
+//  VC6 will fail to compile if class-scope templates
+//     are used to handle arbitrary insertion operations.
+//     However, using global namespace insertion operations 
+//     run into LOGCXX-150.
+
 /**
  *  Template to allow any class with an std::basic_ostream inserter
  *    to be applied to this class.
@@ -419,6 +455,7 @@
      }
      return os;
 }
+#endif
 #endif
 
 #if !defined(LOG4CXX_ENDMSG)

Modified: logging/log4cxx/trunk/src/test/cpp/streamtestcase.cpp
URL: 
http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/test/cpp/streamtestcase.cpp?rev=593286&r1=593285&r2=593286&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/test/cpp/streamtestcase.cpp (original)
+++ logging/log4cxx/trunk/src/test/cpp/streamtestcase.cpp Thu Nov  8 12:07:09 
2007
@@ -403,3 +403,37 @@
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(StreamTestCase);
+
+
+//
+//   The following code tests compilation errors
+//      around bug LOGCXX-150 and is not intended to be executed.
+//
+
+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::getDebug());
+}
+
+void Bar::fn()
+{
+  lout << "hi" << LOG4CXX_ENDMSG;
+}
+


Reply via email to