[llvm-bugs] [Bug 39348] New: cplusplus.NewDeleteLeaks false positive on code using gmock

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Oct 18 19:05:51 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=39348

            Bug ID: 39348
           Summary: cplusplus.NewDeleteLeaks false positive on code using
                    gmock
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
          Assignee: dcoughlin at apple.com
          Reporter: alexfh at google.com
                CC: llvm-bugs at lists.llvm.org

#include "gmock.h"
#include "gunit.h"

using ::testing::Return;

int n;

TEST(A, B) {
  Return(true);

  ASSERT_EQ(n, 1);
}


$ clang-tidy -checks=-*,clang-analyzer*,-clang-analyzer-optin* q.cc -extra-arg
-Xclang=-analyzer-display-progress -extra-arg
-Xclang=-analyze-function="A_B_Test::TestBody()"
ANALYZE (Syntax): q.cc A_B_Test::TestBody()
ANALYZE (Path,  Inline_Regular): q.cc A_B_Test::TestBody()
16 warnings generated.
q.cc:11:3: warning: Potential leak of memory pointed to by field 'value_'
[clang-analyzer-cplusplus.NewDeleteLeaks]
  ASSERT_EQ(n, 1);
  ^
gtest.h:2022:32: note: expanded from macro 'ASSERT_EQ'
# define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
                               ^
gtest.h:2004:23: note: expanded from macro 'GTEST_ASSERT_EQ'
  ASSERT_PRED_FORMAT2(::testing::internal:: \
                      ^
q.cc:9:3: note: Calling 'Return<bool>'
  Return(true);
  ^
gmock-actions.h:1121:10: note: Calling constructor for 'ReturnAction<bool>'
  return internal::ReturnAction<R>(std::move(value));
         ^
gmock-actions.h:569:43: note: Memory is allocated
  explicit ReturnAction(R value) : value_(new R(std::move(value))) {}
                                          ^
gmock-actions.h:1121:10: note: Returning from constructor for
'ReturnAction<bool>'
  return internal::ReturnAction<R>(std::move(value));
         ^
q.cc:9:3: note: Returned allocated memory
  Return(true);
  ^
Suppressed 17 warnings (2 NOLINT, 15 with check filters).


I'll try to provide a hermetic reproduction later.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20181019/431cb52b/attachment.html>


More information about the llvm-bugs mailing list