<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - cplusplus.NewDeleteLeaks false positive on code using gmock"
   href="https://bugs.llvm.org/show_bug.cgi?id=39348">39348</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>cplusplus.NewDeleteLeaks false positive on code using gmock
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Static Analyzer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>dcoughlin@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>alexfh@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>#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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>