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 <burelc@amazon.com>
This commit is contained in:
+2
@@ -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::sys_time_t>(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])
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user