diff options
author | dim <dim@FreeBSD.org> | 2015-12-30 11:49:41 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2015-12-30 11:49:41 +0000 |
commit | 3176e97f130184ece0e1a21352c8124cc83ff24a (patch) | |
tree | 0a5b74c0b9ca73aded34df95c91fcaf3815230d8 /test/Analysis/lambdas-generalized-capture.cpp | |
parent | 1e9b8d38881c3213d1e67b0c47ab9b2c00721a5c (diff) | |
download | FreeBSD-src-3176e97f130184ece0e1a21352c8124cc83ff24a.zip FreeBSD-src-3176e97f130184ece0e1a21352c8124cc83ff24a.tar.gz |
Vendor import of clang trunk r256633:
https://llvm.org/svn/llvm-project/cfe/trunk@256633
Diffstat (limited to 'test/Analysis/lambdas-generalized-capture.cpp')
-rw-r--r-- | test/Analysis/lambdas-generalized-capture.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/test/Analysis/lambdas-generalized-capture.cpp b/test/Analysis/lambdas-generalized-capture.cpp new file mode 100644 index 0000000..790e15e --- /dev/null +++ b/test/Analysis/lambdas-generalized-capture.cpp @@ -0,0 +1,50 @@ +// RUN: %clang_cc1 -std=c++14 -fsyntax-only -analyze -analyzer-checker=core,deadcode,debug.ExprInspection -verify %s + +int clang_analyzer_eval(int); + +void generalizedCapture() { + int v = 7; + auto lambda = [x=v]() { + return x; + }; + + int result = lambda(); + clang_analyzer_eval(result == 7); // expected-warning {{TRUE}} +} + +void sideEffectsInGeneralizedCapture() { + int v = 7; + auto lambda = [x=v++]() { + return x; + }; + clang_analyzer_eval(v == 8); // expected-warning {{TRUE}} + + int r1 = lambda(); + int r2 = lambda(); + clang_analyzer_eval(r1 == 7); // expected-warning {{TRUE}} + clang_analyzer_eval(r2 == 7); // expected-warning {{TRUE}} + clang_analyzer_eval(v == 8); // expected-warning {{TRUE}} +} + +int addOne(int p) { + return p + 1; +} + +void inliningInGeneralizedCapture() { + int v = 7; + auto lambda = [x=addOne(v)]() { + return x; + }; + + int result = lambda(); + clang_analyzer_eval(result == 8); // expected-warning {{TRUE}} +} + +void caseSplitInGeneralizedCapture(bool p) { + auto lambda = [x=(p ? 1 : 2)]() { + return x; + }; + + int result = lambda(); + clang_analyzer_eval(result == 1); // expected-warning {{FALSE}} expected-warning {{TRUE}} +} |