Summary:public Implementation of std::move is straightforward and infer understands it without any problems. To use it, we translate it even though it's coming from system headers. Reviewed By: jvillard Differential Revision: D3064019 fb-gh-sync-id: 823ae75 shipit-source-id: 823ae75master
parent
ab1ac822f6
commit
0a32ff4400
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2016 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#include <utility>
|
||||
|
||||
struct X {
|
||||
X() : f(1) {}
|
||||
X(X&& x) {
|
||||
f = x.f;
|
||||
x.f = 0; // assign zero to field of moved_from object
|
||||
}
|
||||
int f;
|
||||
};
|
||||
|
||||
int div0_moved_from() {
|
||||
X x1;
|
||||
X x2 = std::move(x1);
|
||||
return 1 / x1.f;
|
||||
}
|
||||
|
||||
int div1_moved_from() {
|
||||
X x1;
|
||||
X x2 = std::move(x1);
|
||||
return 1 / (x1.f + 1);
|
||||
}
|
||||
|
||||
int div1_moved_to() {
|
||||
X x1;
|
||||
X x2 = std::move(x1);
|
||||
return 1 / x2.f;
|
||||
}
|
||||
|
||||
int div0_moved_to() {
|
||||
X x1;
|
||||
X x2 = std::move(x1);
|
||||
return 1 / (x2.f - 1);
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2016 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package endtoend.cpp;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static utils.matchers.ResultContainsExactly.containsExactly;
|
||||
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import utils.DebuggableTemporaryFolder;
|
||||
import utils.InferException;
|
||||
import utils.InferResults;
|
||||
import utils.InferRunner;
|
||||
|
||||
public class MoveModelTest {
|
||||
|
||||
public static final String FILE =
|
||||
"infer/tests/codetoanalyze/cpp/errors/models/move.cpp";
|
||||
|
||||
private static ImmutableList<String> inferCmd;
|
||||
|
||||
public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO";
|
||||
|
||||
@ClassRule
|
||||
public static DebuggableTemporaryFolder folder =
|
||||
new DebuggableTemporaryFolder();
|
||||
|
||||
@BeforeClass
|
||||
public static void runInfer() throws InterruptedException, IOException {
|
||||
inferCmd = InferRunner.createCPPInferCommand(folder, FILE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInferRunsOnDiv0FunctionsErrorIsFound()
|
||||
throws InterruptedException, IOException, InferException {
|
||||
String[] procedures = {
|
||||
"div0_moved_from",
|
||||
"div0_moved_to",
|
||||
};
|
||||
InferResults inferResults = InferRunner.runInferCPP(inferCmd);
|
||||
assertThat(
|
||||
"Results should contain divide by 0 error",
|
||||
inferResults,
|
||||
containsExactly(
|
||||
DIVIDE_BY_ZERO,
|
||||
FILE,
|
||||
procedures
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue