diff options
| author | Marc Mutz <marc.mutz@qt.io> | 2023-03-14 16:23:31 +0100 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2023-03-22 15:59:10 +0000 |
| commit | eb9c8042cfa71f16cda27cdeb052d84a6cc117d7 (patch) | |
| tree | 5b960d595636de7eb6faf21f286f15d6c75915bf /src | |
| parent | eafe57704144af6e14899ea904e5e8cb7431a90b (diff) | |
| download | qtbase-eb9c8042cfa71f16cda27cdeb052d84a6cc117d7.tar.gz | |
Short live QT_ENABLE_P0846_SEMANTICS_FOR!
In C++17, unqualified lookup doesn't find function templates that
require ADL from a call with explicit template arguments, unless
another function template of that name is in scope (otherwise, the <
is parsed as operator less-than instead).
P0846, merged for C++20, fixes this to repeat the name lookup, parsing
the < as indicating a template.
We have API in Qt (Tuple Protocol for some types, e.g. QPoint) that
work for the purpose of Structured Bindings, but don't work for manual
unqualified calls when P0846 semantics are missing, and we're adding
more, to QVariant, so add a macro to handle the issue.
The macro simply declares a function template overload of the given
name for a throw-away struct, thereby bringing, for that one name,
P0846 semantics into C++17.
When we require C++20, we can drop this again.
Amends:
- fb6b7869e8bdda94f7e791db7f281f3bb6e0e004 for QPoint(F)
- 8ae9431c792f14a32909ac013a1383547d6bcfa8 for QMargins(F)
- 0e22001a3bb070d4e9956e89543ec0e5ac6f23f8 for the rest
[ChangeLog][QtCore][QSize/F, QMargins/F, QPoint/F] Fixed manual
get<I>() calls (Tuple Protocol) in C++17 mode.
Task-number: QTBUG-111598
Change-Id: I2ffaef12c5bb6d82f75ce78a7c03c6789dfa0691
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/corelib/global/qcompilerdetection.h | 14 | ||||
| -rw-r--r-- | src/corelib/tools/qmargins.h | 2 | ||||
| -rw-r--r-- | src/corelib/tools/qpoint.h | 2 | ||||
| -rw-r--r-- | src/corelib/tools/qsize.h | 2 |
4 files changed, 20 insertions, 0 deletions
diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index cbea1a8024..5baa69270e 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -1358,6 +1358,20 @@ QT_WARNING_DISABLE_MSVC(4530) /* C++ exception handler used, but unwind semantic # endif #endif +#if __cplusplus >= 202002L // P0846 doesn't have a feature macro :/ +# define QT_COMPILER_HAS_P0846 +#endif + +#ifdef QT_COMPILER_HAS_P0846 +# define QT_ENABLE_P0846_SEMANTICS_FOR(func) +#else + class QT_CLASS_JUST_FOR_P0846_SIMULATION; +# define QT_ENABLE_P0846_SEMANTICS_FOR(func) \ + template <typename T> \ + void func (QT_CLASS_JUST_FOR_P0846_SIMULATION *); \ + /* end */ +#endif // !P0846 + #endif // __cplusplus #endif // QCOMPILERDETECTION_H diff --git a/src/corelib/tools/qmargins.h b/src/corelib/tools/qmargins.h index 0b4f74e9dd..f8d7150dfd 100644 --- a/src/corelib/tools/qmargins.h +++ b/src/corelib/tools/qmargins.h @@ -11,6 +11,8 @@ QT_BEGIN_NAMESPACE +QT_ENABLE_P0846_SEMANTICS_FOR(get) + class QMarginsF; /***************************************************************************** diff --git a/src/corelib/tools/qpoint.h b/src/corelib/tools/qpoint.h index 425948966d..7df4d49005 100644 --- a/src/corelib/tools/qpoint.h +++ b/src/corelib/tools/qpoint.h @@ -15,6 +15,8 @@ struct CGPoint; QT_BEGIN_NAMESPACE +QT_ENABLE_P0846_SEMANTICS_FOR(get) + class QPointF; class QPoint diff --git a/src/corelib/tools/qsize.h b/src/corelib/tools/qsize.h index dac2a48908..a5eaf34afe 100644 --- a/src/corelib/tools/qsize.h +++ b/src/corelib/tools/qsize.h @@ -17,6 +17,8 @@ struct CGSize; QT_BEGIN_NAMESPACE +// QT_ENABLE_P0846_SEMANTICS_FOR(get) // from qmargins.h + class QSizeF; class Q_CORE_EXPORT QSize |
