diff options
| author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2025-11-27 23:17:03 +0100 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2025-12-02 10:53:13 +0000 |
| commit | 6d3313df6f1c697c80a6144d37798c83fcbd864e (patch) | |
| tree | a0ef062ce19784584deb69ce4243aead6626de85 | |
| parent | aa6be092307e19dafb623a87df711d148f793fd1 (diff) | |
tst_qxp_is_virtual_base_of: fix a test towards ambiguous bases
If a derived class inherits from the same base class both virtually and
non-virtually, our implementation of the is_virtual_base_of trait cannot
properly detect this due to the ambiguity, and will answer "false". On
the other hand the version shipping in C++26 will correctly answer
"true" (there *is* a virtual inheritance path).
Amend the test to take this into account.
Practically speaking, this behavioral difference isn't a cause of
concern: this trait is used to guard conversions of pointers from
derived classes towards base classes. That implies that the inheritance
is not ambiguous (otherwise the pointer wouldn't be convertible to begin
with).
Amends 35878fa924d0598b1cdec5ba358e8488f6774676.
Task-number: QTBUG-138246
Pick-to: 6.10 6.8
Change-Id: I5b115a826202d1fb6c793678d4660c847c1a7c71
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
| -rw-r--r-- | tests/auto/corelib/global/qxp/is_virtual_base_of/tst_is_virtual_base_of.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/tests/auto/corelib/global/qxp/is_virtual_base_of/tst_is_virtual_base_of.cpp b/tests/auto/corelib/global/qxp/is_virtual_base_of/tst_is_virtual_base_of.cpp index e50575f5eca..06af4d81319 100644 --- a/tests/auto/corelib/global/qxp/is_virtual_base_of/tst_is_virtual_base_of.cpp +++ b/tests/auto/corelib/global/qxp/is_virtual_base_of/tst_is_virtual_base_of.cpp @@ -58,9 +58,15 @@ class AmbiguousBase1 : public IntermediateDerived, public Base {}; class AmbiguousBase2 : public IntermediateDerived, public virtual Base {}; static_assert(!qxp::is_virtual_base_of_v<Base, AmbiguousBase1>); +#ifdef __cpp_lib_is_virtual_base_of +// Our own implementation cannot handle ambiguous bases correctly; +// the stdlib one does. +static_assert(qxp::is_virtual_base_of_v<Base, AmbiguousBase2>); +#else #ifndef Q_CC_MSVC_ONLY // https://developercommunity.visualstudio.com/t/c-templates-multiple-inheritance-ambiguous-access/185674 static_assert(!qxp::is_virtual_base_of_v<Base, AmbiguousBase2>); #endif +#endif QT_WARNING_POP // Const |
