From 369b8fd06f712e5f34c8c48ac0baf69362c26790 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 24 Aug 2026 15:54:21 +0000 Subject: [PATCH] Fix top-of-tree Clang build warnings (#7670) `-Wunused-template` was added to `-Wunused`, so clean up the things it found. One of them was a bug in the Clang warning that I've worked around and reported upstream: https://github.com/llvm/llvm-project/issues/218429 --- common/hashing_test.cpp | 35 -------------------------- testing/base/capture_std_streams.h | 4 +-- toolchain/check/deduce.cpp | 5 ---- toolchain/check/eval.cpp | 13 ++++------ toolchain/driver/clang_runner_test.cpp | 24 ------------------ 5 files changed, 7 insertions(+), 74 deletions(-) diff --git a/common/hashing_test.cpp b/common/hashing_test.cpp index 68c42ba1475b..4522e8368774 100644 --- a/common/hashing_test.cpp +++ b/common/hashing_test.cpp @@ -491,41 +491,6 @@ struct HashedValue { using HashedString = HashedValue; -template -auto PrintFullWidthHex(llvm::raw_ostream& os, T value) { - static_assert(sizeof(T) == 1 || sizeof(T) == 2 || sizeof(T) == 4 || - sizeof(T) == 8); - // Given the nature of a format string and the good formatting, a nested - // conditional seems like the most readable structure. - // NOLINTBEGIN(readability-avoid-nested-conditional-operator) - os << llvm::formatv(sizeof(T) == 1 ? "{0:x2}" - : sizeof(T) == 2 ? "{0:x4}" - : sizeof(T) == 4 ? "{0:x8}" - : "{0:x16}", - static_cast(value)); - // NOLINTEND(readability-avoid-nested-conditional-operator) -} - -template - requires std::integral -auto operator<<(llvm::raw_ostream& os, HashedValue hv) - -> llvm::raw_ostream& { - os << "hash " << hv.hash << " for value "; - PrintFullWidthHex(os, hv.v); - return os; -} - -template - requires std::integral && std::integral -auto operator<<(llvm::raw_ostream& os, HashedValue> hv) - -> llvm::raw_ostream& { - os << "hash " << hv.hash << " for pair of "; - PrintFullWidthHex(os, hv.v.first); - os << " and "; - PrintFullWidthHex(os, hv.v.second); - return os; -} - struct Collisions { int total; int median; diff --git a/testing/base/capture_std_streams.h b/testing/base/capture_std_streams.h index 7e33822216a5..6cff8a581885 100644 --- a/testing/base/capture_std_streams.h +++ b/testing/base/capture_std_streams.h @@ -24,8 +24,8 @@ auto EndStdStreamCapture(std::string& out, std::string& err) -> void; // print back out or otherwise expose any of the contents of the captured output // that are needed when debugging. template -static auto CallWithCapturedOutput(std::string& out, std::string& err, - FnT function) -> auto { +auto CallWithCapturedOutput(std::string& out, std::string& err, FnT function) + -> auto { Internal::BeginStdStreamCapture(); auto result = function(); Internal::EndStdStreamCapture(out, err); diff --git a/toolchain/check/deduce.cpp b/toolchain/check/deduce.cpp index 64ae0e877ab7..67913084a0de 100644 --- a/toolchain/check/deduce.cpp +++ b/toolchain/check/deduce.cpp @@ -196,11 +196,6 @@ class DeductionContext { worklist_.AddAll(params, args, want_value); } - template - auto AddAll(ParamT param, ArgT arg) -> void { - worklist_.AddAll(param, arg); - } - // Performs all deductions in the deduction worklist. Returns whether // deduction succeeded. auto Deduce() -> bool; diff --git a/toolchain/check/eval.cpp b/toolchain/check/eval.cpp index 808707079859..c68eaf11e445 100644 --- a/toolchain/check/eval.cpp +++ b/toolchain/check/eval.cpp @@ -923,8 +923,12 @@ static auto ReplaceFieldWithConstantValue(EvalContext& eval_context, // Function template that can be called with an argument of type `T`. Used below // to detect which overloads of `GetConstantValue` exist. +// +// Marked as maybe unused at it seems the use in a requires isn't tracked by the +// latest version of Clang's `-Wunused-template`. +// https://github.com/llvm/llvm-project/issues/218429 template -static void Accept(T /*arg*/) {} +[[maybe_unused]] static auto Accept(T /*arg*/) -> void {} // Determines whether a `GetConstantValue` overload exists for a given ID type. // Note that we do not check whether `GetConstantValue` is *callable* with a @@ -998,13 +1002,6 @@ static auto ReplaceTypeWithConstantValue(EvalContext& eval_context, return IsConstantOrError(*phase); } -template -static auto KindHasGetConstantValueOverload(TypeEnum e) -> bool { - static constexpr std::array Values = { - (HasGetConstantValueOverload)...}; - return Values[e.ToIndex()]; -} - static auto ResolveSpecificDeclForSpecificId(EvalContext& eval_context, SemIR::SpecificId specific_id) -> void { diff --git a/toolchain/driver/clang_runner_test.cpp b/toolchain/driver/clang_runner_test.cpp index 10ff836ba93b..456d0969fdc2 100644 --- a/toolchain/driver/clang_runner_test.cpp +++ b/toolchain/driver/clang_runner_test.cpp @@ -33,30 +33,6 @@ using ::testing::HasSubstr; using Testing::IsSuccess; using ::testing::StrEq; -// NOLINTNEXTLINE(modernize-use-trailing-return-type): Macro based function. -MATCHER_P(TextSymbolNamed, name_matcher, "") { - llvm::Expected name = arg.getName(); - if (auto error = name.takeError()) { - *result_listener << "with an error instead of a name: " << error; - return false; - } - if (!testing::ExplainMatchResult(name_matcher, *name, result_listener)) { - return false; - } - // We have to dig out the section to determine if this was a text symbol. - auto expected_section_it = arg.getSection(); - if (auto error = expected_section_it.takeError()) { - *result_listener << "without a section: " << error; - return false; - } - llvm::object::SectionRef section = **expected_section_it; - if (!section.isText()) { - *result_listener << "in the non-text section: " << *section.getName(); - return false; - } - return true; -} - class ClangRunnerTest : public ::testing::Test { public: InstallPaths install_paths_ =