Only include <format> if __cpp_lib_format is defined

With C++ 17, MSVC evaluates __has_include(<format>) to true and does not
prevent inclusion of the <format> header. This leads to build warnings:

    STL4038: The contents of <format> are available only with C++20 or
    later.

Because of similar issues with GCC, we stopped using __has_include for
feature detection, and instead require C++20 <version> to be available,
even in C++17 builds, cf. b2ed29b8d9b33dcece83000aee28073dd27f1cd9.

Since we include <version> centrally these days, we can just use the
feature test macro, __cpp_lib_format, directly.

Amends ffac33964d51971a1c1f61308b6f0a60a4133296.

Task-number: QTBUG-104654
Pick-to: 6.8
Change-Id: Ie923af92a7f8ab19cbd9cac9307f3f2e9a72e316
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Jøger Hansegård 2024-06-19 16:12:14 +02:00 committed by Marc Mutz
parent c95873400f
commit cf9b8b4633

View File

@ -12,12 +12,9 @@
#include <QtCore/qsystemdetection.h>
#include <QtCore/qtconfigmacros.h>
#if __has_include(<format>)
# include <format>
#endif
#if (defined(__cpp_lib_format) && (__cpp_lib_format >= 202106L))
#include <format>
#define QT_SUPPORTS_STD_FORMAT 1
#endif // __cpp_lib_format