From ea2d0bec1f8a2ea05e22b3227d6e28672a24d966 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 27 Apr 2025 09:08:44 -0700 Subject: [PATCH 1/2] [Support] Simplify setDefaultImpl (NFC) We can use "constexpr if" to combine the two variants of functions. --- llvm/include/llvm/Support/CommandLine.h | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h index 5d60bb64bbb20..4c9f5bae87759 100644 --- a/llvm/include/llvm/Support/CommandLine.h +++ b/llvm/include/llvm/Support/CommandLine.h @@ -1459,18 +1459,16 @@ class opt } } - template >> - void setDefaultImpl() { - const OptionValue &V = this->getDefault(); - if (V.hasValue()) - this->setValue(V.getValue()); - else - this->setValue(T()); + template void setDefaultImpl() { + if constexpr (std::is_assignable_v) { + const OptionValue &V = this->getDefault(); + if (V.hasValue()) + this->setValue(V.getValue()); + else + this->setValue(T()); + } } - template >> - void setDefaultImpl(...) {} - void setDefault() override { setDefaultImpl(); } void done() { From 3d437a2530821d2fc79573faf2e2453469304f62 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 27 Apr 2025 12:47:22 -0700 Subject: [PATCH 2/2] Address a comment. --- llvm/include/llvm/Support/CommandLine.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h index 4c9f5bae87759..531750572102c 100644 --- a/llvm/include/llvm/Support/CommandLine.h +++ b/llvm/include/llvm/Support/CommandLine.h @@ -1459,18 +1459,16 @@ class opt } } - template void setDefaultImpl() { - if constexpr (std::is_assignable_v) { + void setDefault() override { + if constexpr (std::is_assignable_v) { const OptionValue &V = this->getDefault(); if (V.hasValue()) this->setValue(V.getValue()); else - this->setValue(T()); + this->setValue(DataType()); } } - void setDefault() override { setDefaultImpl(); } - void done() { addArgument(); Parser.initialize();