Closed
Description
Clang-Tidy produces a false positive when returning from a lambda:
returning a newly created resource of type 'void' or 'gsl::owner<>' from a function whose return type is not 'gsl::owner<>'C/C++cppcoreguidelines-owning-memory
Is caused by:
TEST(ExternalLibTest, MicrosoftGslOwner)
{
struct S
{
int value{1};
};
const auto MakeS = [] -> ::gsl::owner<S*>
{
return ::gsl::owner<S*>{new S{}};
};
const ::gsl::owner<S*> sPtr = MakeS();
EXPECT_EQ(sPtr->value, 1);
EXPECT_NE(sPtr->value, 2);
}
but this is fine:
namespace {
struct S
{
int value{1};
};
auto MakeS()
{
return ::gsl::owner<S*>{new S{}};
}
} // namespace