summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLincoln Ramsay <lincoln.ramsay@nokia.com>2012-05-31 16:51:25 +1000
committerZsolt Simon <zsolt.simon@nokia.com>2012-06-01 00:54:37 +0200
commit17c1484ff2cddd61879d9bac253468d5da4766a8 (patch)
tree7641282a2c8b438c96ca772096ae76e03cf843cf
parent5cfe3884f9452f8c39351e185596db9a7376769b (diff)
Re-define the macros to avoid ambiguous else warnings.
Using if (condition) qCDebug(CAT) << "message"; provokes an ambiguous else warning from the compiler. Using this form of loop avoids this warning yet compiles to the same quick "do nothing" logic. Change-Id: Ic8b025de5b6270dc981c9736201c8105a697c39c Reviewed-by: Zsolt Simon <zsolt.simon@nokia.com>
-rw-r--r--src/logger/qlogger.h40
1 files changed, 14 insertions, 26 deletions
diff --git a/src/logger/qlogger.h b/src/logger/qlogger.h
index 84bb5c7..1877c5c 100644
--- a/src/logger/qlogger.h
+++ b/src/logger/qlogger.h
@@ -77,55 +77,43 @@ QT_LOGGER_USE_NAMESPACE
# undef qDebug
#endif
-#define qDebug \
- if (!QLoggingCategory::defaultCategory().isEnabled(QtDebugMsg)) \
- /*NOP*/; \
- else \
- QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, QLoggingCategory::defaultCategory().categoryName()).debug
+#define qDebug \
+ for (bool enabled = QLoggingCategory::defaultCategory().isEnabled(QtDebugMsg); enabled; enabled = false) \
+ QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, QLoggingCategory::defaultCategory().categoryName()).debug
#if defined(qWarning)
# undef qWarning
#endif
-#define qWarning \
- if (!QLoggingCategory::defaultCategory().isEnabled(QtWarningMsg)) \
- /*NOP*/; \
- else \
+#define qWarning \
+ for (bool enabled = QLoggingCategory::defaultCategory().isEnabled(QtWarningMsg); enabled; enabled = false) \
QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, QLoggingCategory::defaultCategory().categoryName()).warning
#if defined(qCritical)
# undef qCritical
#endif
-#define qCritical \
- if (!QLoggingCategory::defaultCategory().isEnabled(QtCriticalMsg)) \
- /*NOP*/; \
- else \
+#define qCritical \
+ for (bool enabled = QLoggingCategory::defaultCategory().isEnabled(QtCriticalMsg); enabled; enabled = false) \
QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, QLoggingCategory::defaultCategory().categoryName()).critical
//This marco creates the QLoggingCategory object in an empty namespace
-//to prevent linker problems if someone else uses the categorytype in an other place.
+//to prevent potential linker problems if someone else uses the same categorytype in another file.
#define QT_LOG_CATEGORY(categorytype, categoryname) \
namespace { \
static QLoggingCategory categorytype(categoryname); \
}
-#define qCDebug(category) \
- if (!category.isEnabled(QtDebugMsg)) \
- /*NOP*/; \
- else \
+#define qCDebug(category) \
+ for (bool enabled = category.isEnabled(QtDebugMsg); enabled; enabled = false) \
QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, category.categoryName()).debug()
-#define qCWarning(category) \
- if (!category.isEnabled(QtWarningMsg)) \
- /*NOP*/; \
- else \
+#define qCWarning(category) \
+ for (bool enabled = category.isEnabled(QtWarningMsg); enabled; enabled = false) \
QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, category.categoryName()).warning()
-#define qCCritical(category) \
- if (!category.isEnabled(QtCriticalMsg)) \
- /*NOP*/; \
- else \
+#define qCCritical(category) \
+ for (bool enabled = category.isEnabled(QtCriticalMsg); enabled; enabled = false) \
QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, category.categoryName()).critical()
#endif // QLOGGER_H