From 41be03f193c5163b209ba255707b7c804048deeb Mon Sep 17 00:00:00 2001 From: Chris Burel Date: Thu, 10 Feb 2022 15:30:39 -0800 Subject: [PATCH] Silence warning about unnecessary lambda captures with clang The `unused-lambda-capture` will be triggered by the following code: ```cpp void foo(int); int main() { const int i = 0; auto l = [i](){foo(i);}; } ``` The issue here is that reading from the constant variable `i` does not constitute an ODR-use, and consequently the variable does not have to be captured. See https://github.com/llvm/llvm-project/issues/34213#issuecomment-980987311 for a related discussion. However, MSVC sees it differently. In order to make both compilers happy, mark this variable with `AZ_UNUSED`, since lambda captures can't be marked with attributes like `[[maybe_unused]]`. Signed-off-by: Chris Burel --- .../Source/Artifact/Factory/TestImpactTestRunSuiteFactory.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactTestRunSuiteFactory.cpp b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactTestRunSuiteFactory.cpp index f39cfaaf10..dfa8c9c49b 100644 --- a/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactTestRunSuiteFactory.cpp +++ b/Code/Tools/TestImpactFramework/Runtime/Code/Source/Artifact/Factory/TestImpactTestRunSuiteFactory.cpp @@ -69,6 +69,7 @@ namespace TestImpact const auto getDuration = [Keys](const AZ::rapidxml::xml_node<>* node) AZ_POP_DISABLE_WARNING { + AZ_UNUSED(Keys); // Clang reports a warning that capturing Keys is not necessary because it is not odr-used const AZStd::string duration = node->first_attribute(Keys[DurationKey])->value(); return AZStd::chrono::milliseconds(static_cast(AZStd::stof(duration) * 1000.f)); }; @@ -86,6 +87,7 @@ namespace TestImpact const auto getStatus = [Keys](const AZ::rapidxml::xml_node<>* node) AZ_POP_DISABLE_WARNING { + AZ_UNUSED(Keys); // Clang reports a warning that capturing Keys is not necessary because it is not odr-used const AZStd::string status = node->first_attribute(Keys[StatusKey])->value(); if (status == Keys[RunKey]) {