PR #2064: docs: document MSVC compile-time format checking limitation in str_format.h Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/2064 Fixes #1478 absl::StrFormat compile-time format string checking relies on __attribute__((format(...))), a GCC/Clang-specific compiler extension that MSVC does not support. This adds a note to the file-level documentation so MSVC users are aware that format string errors will only be caught at runtime, not at compile time. Merge 81977d79547f3a4e35dd3ce1c2ad54b1de2fcb65 into e7a10c8ec2ab4a251d1523812f10318431f1a14a Merging this change closes #2064 COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/2064 from DrishtiTripathi2230:docs/strformat-msvc-compile-time-check 81977d79547f3a4e35dd3ce1c2ad54b1de2fcb65 PiperOrigin-RevId: 922922072 Change-Id: I91f545b6a1e64f3d8aba3350ac6332cb9548a40a
diff --git a/absl/strings/str_format.h b/absl/strings/str_format.h index ffa7f11..18a21a9 100644 --- a/absl/strings/str_format.h +++ b/absl/strings/str_format.h
@@ -49,7 +49,8 @@ // * A `FormatSpec` class template fully encapsulates a format string and its // type arguments and is usually provided to `str_format` functions as a // variadic argument of type `FormatSpec<Arg...>`. The `FormatSpec<Args...>` -// template is evaluated at compile-time, providing type safety. +// template is evaluated at compile-time, providing type safety (supported +// on GCC and Clang; on MSVC, these checks are deferred to runtime). // * A `ParsedFormat` instance, which encapsulates a specific, pre-compiled // format string for a specific set of type(s), and which can be passed // between API boundaries. (The `FormatSpec` type should not be used @@ -275,7 +276,9 @@ // any string-like argument, so `std::string`, `std::wstring`, // `absl::string_view`, `const char*`, and `const wchar_t*` are all accepted. // Likewise, `%d` accepts any integer-like argument, etc. - +// +// Note: Compile-time format string checking is supported on GCC and +// Clang. On MSVC, these checks are performed at runtime instead. template <typename... Args> using FormatSpec = str_format_internal::FormatSpecTemplate< str_format_internal::ArgumentToConv<Args>()...>;