diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2021-02-10 00:45:53 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-10 08:01:47 +0100 |
commit | 338bb732898dbf68db9554e6a32b4a89ccabb891 (patch) | |
tree | 9c3c947b767c0c4ea59eb78f6162bcf0303ba583 | |
parent | 1fd349b8c2967c28033a08a71368a0b383be5203 (diff) | |
download | serenity-338bb732898dbf68db9554e6a32b4a89ccabb891.zip |
AK: Fix build with Clang>=12
Build failure as in https://oss-fuzz-build-logs.storage.googleapis.com/log-79750138-f41e-4f39-8812-7c536f1d2e35.txt
Clang does not appear to like using consteval functions' arguments as
constant expressions, so move all the arguments that need to appear as
constant expressions into the template parameters for now.
This patch should fix the OSS-Fuzz build.
-rw-r--r-- | AK/Format.h | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/AK/Format.h b/AK/Format.h index ede7a2585a..46ac4d616f 100644 --- a/AK/Format.h +++ b/AK/Format.h @@ -38,7 +38,7 @@ #endif #ifndef DBGLN_NO_COMPILETIME_FORMAT_CHECK -// Note: Clang 12 adds support for CTAD, this would fail with any version prior to that. +// Note: Clang 12 adds support for CTAD on NTTPs, this would fail with any version prior to that. # if defined(__clang__) && __clang_major__ < 12 # define DBGLN_NO_COMPILETIME_FORMAT_CHECK # endif @@ -47,15 +47,15 @@ #ifndef DBGLN_NO_COMPILETIME_FORMAT_CHECK namespace { -template<size_t N> -consteval auto extract_used_argument_index(const char (&fmt)[N], size_t specifier_start_index, size_t specifier_end_index, size_t& next_implicit_argument_index) +template<size_t N, StringLiteral<N> fmt> +consteval auto extract_used_argument_index(size_t specifier_start_index, size_t specifier_end_index, size_t& next_implicit_argument_index) { struct { size_t index_value { 0 }; bool saw_explicit_index { false }; } state; for (size_t i = specifier_start_index; i < specifier_end_index; ++i) { - auto c = fmt[i]; + auto c = fmt.data[i]; if (c > '9' || c < '0') break; @@ -71,8 +71,8 @@ consteval auto extract_used_argument_index(const char (&fmt)[N], size_t specifie } // FIXME: We should rather parse these format strings at compile-time if possible. -template<size_t N> -consteval auto count_fmt_params(const char (&fmt)[N]) +template<size_t N, StringLiteral<N> fmt> +consteval auto count_fmt_params() { struct { // FIXME: Switch to variable-sized storage whenever we can come up with one :) @@ -91,10 +91,10 @@ consteval auto count_fmt_params(const char (&fmt)[N]) } result; for (size_t i = 0; i < N; ++i) { - auto ch = fmt[i]; + auto ch = fmt.data[i]; switch (ch) { case '{': - if (i + 1 < N && fmt[i + 1] == '{') { + if (i + 1 < N && fmt.data[i + 1] == '{') { ++i; continue; } @@ -108,7 +108,7 @@ consteval auto count_fmt_params(const char (&fmt)[N]) ++result.unclosed_braces; break; case '}': - if (i + 1 < N && fmt[i + 1] == '}') { + if (i + 1 < N && fmt.data[i + 1] == '}') { ++i; continue; } @@ -123,7 +123,7 @@ consteval auto count_fmt_params(const char (&fmt)[N]) if (result.total_used_argument_count >= result.used_arguments.size()) result.internal_error = "Format-String Checker internal error: Too many format arguments in format string"; - auto used_argument_index = extract_used_argument_index<N>(fmt, specifier_start_index, i, result.next_implicit_argument_index); + auto used_argument_index = extract_used_argument_index<N, fmt>(specifier_start_index, i, result.next_implicit_argument_index); if (used_argument_index + 1 != result.next_implicit_argument_index) result.has_explicit_argument_references = true; result.used_arguments[result.total_used_argument_count++] = used_argument_index; @@ -140,7 +140,7 @@ consteval auto count_fmt_params(const char (&fmt)[N]) } } -template<size_t N, StringLiteral<N> fmt, size_t param_count, auto check = count_fmt_params<N>(fmt.data)> +template<size_t N, StringLiteral<N> fmt, size_t param_count, auto check = count_fmt_params<N, fmt>()> constexpr bool check_format_parameter_consistency() { static_assert(check.internal_error.data[0] == 0, "Some internal error occured, try looking at the check function type for the error"); |