Fix namespace error of std::source_location under C++20
With C++20 standard, src/corelib/kernel/qproperty.h of Qt Base cannot be compiled at line 100: QPropertyBindingSourceLocation( const std::experimental::source_location &cppLocation ) The reason is that source_location has been merged into namespace std since C++20, and the header file has also been change from <experimental/source_location> to <source_location>. The problem can be avoided by define a constant. Fixes: QTBUG-93270 Change-Id: I46b4daac6ea20f9623b43746880500d41396afb2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
627542c841
commit
675a4b0cc7
@ -50,11 +50,13 @@
|
||||
#include <QtCore/qpropertyprivate.h>
|
||||
|
||||
#if __has_include(<source_location>) && __cplusplus >= 202002L && !defined(Q_CLANG_QDOC)
|
||||
#include <experimental/source_location>
|
||||
#include <source_location>
|
||||
#define QT_SOURCE_LOCATION_NAMESPACE std
|
||||
#define QT_PROPERTY_COLLECT_BINDING_LOCATION
|
||||
#define QT_PROPERTY_DEFAULT_BINDING_LOCATION QPropertyBindingSourceLocation(std::source_location::current())
|
||||
#elif __has_include(<experimental/source_location>) && __cplusplus >= 201703L && !defined(Q_CLANG_QDOC)
|
||||
#include <experimental/source_location>
|
||||
#define QT_SOURCE_LOCATION_NAMESPACE std::experimental
|
||||
#define QT_PROPERTY_COLLECT_BINDING_LOCATION
|
||||
#define QT_PROPERTY_DEFAULT_BINDING_LOCATION QPropertyBindingSourceLocation(std::experimental::source_location::current())
|
||||
#else
|
||||
@ -102,7 +104,7 @@ struct Q_CORE_EXPORT QPropertyBindingSourceLocation
|
||||
quint32 column = 0;
|
||||
QPropertyBindingSourceLocation() = default;
|
||||
#ifdef QT_PROPERTY_COLLECT_BINDING_LOCATION
|
||||
QPropertyBindingSourceLocation(const std::experimental::source_location &cppLocation)
|
||||
QPropertyBindingSourceLocation(const QT_SOURCE_LOCATION_NAMESPACE::source_location &cppLocation)
|
||||
{
|
||||
fileName = cppLocation.file_name();
|
||||
functionName = cppLocation.function_name();
|
||||
@ -1199,6 +1201,8 @@ public:
|
||||
} \
|
||||
QObjectComputedProperty<Class, Type, Class::_qt_property_##name##_offset, __VA_ARGS__> name;
|
||||
|
||||
#undef QT_SOURCE_LOCATION_NAMESPACE
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QPROPERTY_H
|
||||
|
@ -32,6 +32,14 @@
|
||||
#include <qproperty.h>
|
||||
#include <private/qproperty_p.h>
|
||||
|
||||
#if __has_include(<source_location>) && __cplusplus >= 202002L && !defined(Q_CLANG_QDOC)
|
||||
#include <source_location>
|
||||
#define QT_SOURCE_LOCATION_NAMESPACE std
|
||||
#elif __has_include(<experimental/source_location>) && __cplusplus >= 201703L && !defined(Q_CLANG_QDOC)
|
||||
#include <experimental/source_location>
|
||||
#define QT_SOURCE_LOCATION_NAMESPACE std::experimental
|
||||
#endif
|
||||
|
||||
using namespace QtPrivate;
|
||||
|
||||
|
||||
@ -466,7 +474,7 @@ void tst_QProperty::dontTriggerDependenciesIfUnchangedValue()
|
||||
void tst_QProperty::bindingSourceLocation()
|
||||
{
|
||||
#if defined(QT_PROPERTY_COLLECT_BINDING_LOCATION)
|
||||
auto bindingLine = std::experimental::source_location::current().line() + 1;
|
||||
auto bindingLine = QT_SOURCE_LOCATION_NAMESPACE::source_location::current().line() + 1;
|
||||
auto binding = Qt::makePropertyBinding([]() { return 42; });
|
||||
QCOMPARE(QPropertyBindingPrivate::get(binding)->sourceLocation().line, bindingLine);
|
||||
#else
|
||||
@ -1803,4 +1811,6 @@ void tst_QProperty::groupedNotificationConsistency()
|
||||
|
||||
QTEST_MAIN(tst_QProperty);
|
||||
|
||||
#undef QT_SOURCE_LOCATION_NAMESPACE
|
||||
|
||||
#include "tst_qproperty.moc"
|
||||
|
Loading…
x
Reference in New Issue
Block a user