From fba0dc2e6a176b4c351f0c8eb5383bb7e28d6c5c Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Tue, 22 Oct 2024 21:25:09 -0700 Subject: [PATCH] [libc] Use `if constexpr` for compile-time conditionals Don't use plain `if` for things that are compile-time constants. Instead, use `if constexpr`. This both ensures that these are properly wired up constant expressions as intended, and prevents warnings from the compiler about useless `if` checks that look in the source like they're meant to do something at runtime but will just be compiled away. --- libc/test/UnitTest/FPMatcher.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libc/test/UnitTest/FPMatcher.h b/libc/test/UnitTest/FPMatcher.h index bdcc22ef94e76..7fcc6a32025b5 100644 --- a/libc/test/UnitTest/FPMatcher.h +++ b/libc/test/UnitTest/FPMatcher.h @@ -124,35 +124,35 @@ template class CFPMatcher : public Matcher { bool match(T actualValue) { actual = actualValue; - if (cpp::is_complex_type_same()) + if constexpr (cpp::is_complex_type_same()) return matchComplex(); - else if (cpp::is_complex_type_same()) + else if constexpr (cpp::is_complex_type_same()) return matchComplex(); - else if (cpp::is_complex_type_same()) + else if constexpr (cpp::is_complex_type_same()) return matchComplex(); #ifdef LIBC_TYPES_HAS_CFLOAT16 - else if (cpp::is_complex_type_same) + else if constexpr (cpp::is_complex_type_same) return matchComplex(); #endif #ifdef LIBC_TYPES_HAS_CFLOAT128 - else if (cpp::is_complex_type_same) + else if constexpr (cpp::is_complex_type_same) return matchComplex(); #endif } void explainError() override { - if (cpp::is_complex_type_same()) + if constexpr (cpp::is_complex_type_same()) return explainErrorComplex(); - else if (cpp::is_complex_type_same()) + else if constexpr (cpp::is_complex_type_same()) return explainErrorComplex(); - else if (cpp::is_complex_type_same()) + else if constexpr (cpp::is_complex_type_same()) return explainErrorComplex(); #ifdef LIBC_TYPES_HAS_CFLOAT16 - else if (cpp::is_complex_type_same) + else if constexpr (cpp::is_complex_type_same) return explainErrorComplex(); #endif #ifdef LIBC_TYPES_HAS_CFLOAT128 - else if (cpp::is_complex_type_same) + else if constexpr (cpp::is_complex_type_same) return explainErrorComplex(); #endif }