[ https://issues.apache.org/jira/browse/LOGCXX-393?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Thorsten Schöning resolved LOGCXX-393. -------------------------------------- Resolution: Fixed This got fixed in LOGCXX-319. > Strange compile error w/ log4cxx, version 0.10.0,gcc version 4.2.1 20070719 > [FreeBSD] > -------------------------------------------------------------------------------------- > > Key: LOGCXX-393 > URL: https://issues.apache.org/jira/browse/LOGCXX-393 > Project: Log4cxx > Issue Type: Improvement > Affects Versions: 0.10.0 > Environment: gcc 4.2.1 > FreeBSD 8.2-RELEASE-p4 (amd64) > Reporter: Jim Carroll > Assignee: Curt Arnold > Priority: Minor > > Quite strange (but minor) issue using log4cxx. The following code snippet > fails to compile: > #include <log4cxx/logger.h> > log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger("fn"); > void fn() { > if (logger->isTraceEnabled()) > LOG4CXX_TRACE(logger, "Trace"); > else if (logger->isDebugEnabled()) > LOG4CXX_DEBUG(logger, "Debug"); > } > Compiled with the following command: g++ -c -I/usr/local/include t2.cpp > Results in: > t2.cpp: In function 'void fn()': > t2.cpp:6: error: expected primary-expression before 'else' > t2.cpp:6: error: expected `;' before 'else' > t2.cpp:8: error: expected `}' at end of input > You can solve the compile error, by enclosing the LOG4CXX_TRACE statement in > braces, thusly: > #include <log4cxx/logger.h> > log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger("fn"); > void fn() { > if (logger->isTraceEnabled()) { > LOG4CXX_TRACE(logger, "Trace"); > } > else if (logger->isDebugEnabled()) > LOG4CXX_DEBUG(logger, "Debug"); > } > Here's where it get's really strange....the compiler only generates the > error, when you have the 'else if' statement immediately following the > LOG4CXX_TRACE() macro. So this piece of code also compiles without errors. > #include <log4cxx/logger.h> > log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger("fn"); > void fn() { > if (logger->isTraceEnabled()) > LOG4CXX_TRACE(logger, "Trace"); > } > I strongly suspect it's some sort of strange artifact of the pre-processor, > but I'm having difficulty figuring out what it specifically doesn't like. > I've attached the pre-processor output below. > Jim C. > ----- > (REMOVED MOST OF THE CPP OUTPUT FOR BREVITY) > # 1910 "/usr/local/include/log4cxx/logger.h" 2 > # 2 "t2.cpp" 2 > log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger("fn"); > void fn() { > if (logger->isTraceEnabled()) > { if (__builtin_expect(logger->isTraceEnabled(), 0)) { > ::log4cxx::helpers::MessageBuffer oss_; > logger->forcedLog(::log4cxx::Level::getTrace(), oss_.str(oss_ << "Trace"), > ::log4cxx::spi::LocationInfo("t2.cpp", __PRETTY_FUNCTION__, 5)); }}; > else if (logger->isDebugEnabled()) > { if (__builtin_expect(logger->isDebugEnabled(), 0)) { > ::log4cxx::helpers::MessageBuffer oss_; > logger->forcedLog(::log4cxx::Level::getDebug(), oss_.str(oss_ << "Debug"), > ::log4cxx::spi::LocationInfo("t2.cpp", __PRETTY_FUNCTION__, 7)); }}; > } -- This message was sent by Atlassian JIRA (v6.1.5#6160)