diff --git a/src/corelib/kernel/qproperty.h b/src/corelib/kernel/qproperty.h index 6672f270f47..1cf06839df3 100644 --- a/src/corelib/kernel/qproperty.h +++ b/src/corelib/kernel/qproperty.h @@ -50,11 +50,13 @@ #include #if __has_include() && __cplusplus >= 202002L && !defined(Q_CLANG_QDOC) -#include +#include +#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() && __cplusplus >= 201703L && !defined(Q_CLANG_QDOC) #include +#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 @@ -97,7 +99,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(); @@ -1195,6 +1197,8 @@ private: } \ QObjectComputedProperty name; +#undef QT_SOURCE_LOCATION_NAMESPACE + QT_END_NAMESPACE #endif // QPROPERTY_H diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp index 6062c231892..4826e062d79 100644 --- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp +++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp @@ -31,6 +31,14 @@ #include #include +#if __has_include() && __cplusplus >= 202002L && !defined(Q_CLANG_QDOC) +#include +#define QT_SOURCE_LOCATION_NAMESPACE std +#elif __has_include() && __cplusplus >= 201703L && !defined(Q_CLANG_QDOC) +#include +#define QT_SOURCE_LOCATION_NAMESPACE std::experimental +#endif + using namespace QtPrivate; @@ -434,7 +442,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 @@ -1596,4 +1604,6 @@ void tst_QProperty::markDirty() QTEST_MAIN(tst_QProperty); +#undef QT_SOURCE_LOCATION_NAMESPACE + #include "tst_qproperty.moc"