| 1 |
// RUN: %clang_analyze_cc1 -std=c++14 -analyzer-checker=core,debug.ExprInspection -analyzer-config inline-lambdas=true -verify %s |
| 2 |
// RUN: %clang_analyze_cc1 -std=c++17 -analyzer-checker=core,debug.ExprInspection -analyzer-config inline-lambdas=true -verify %s |
| 3 |
|
| 4 |
#include "Inputs/system-header-simulator-cxx.h" |
| 5 |
|
| 6 |
void clang_analyzer_warnIfReached(); |
| 7 |
void clang_analyzer_eval(int); |
| 8 |
|
| 9 |
// Capture copy elided object. |
| 10 |
struct Elided{ |
| 11 |
int x = 14; |
| 12 |
Elided(int) {} |
| 13 |
}; |
| 14 |
|
| 15 |
void testCopyElidedObjectCaptured(int x) { |
| 16 |
int r = [e = Elided(x)] { |
| 17 |
return e.x; |
| 18 |
}(); |
| 19 |
|
| 20 |
clang_analyzer_eval(r == 14); // expected-warning{{TRUE}} |
| 21 |
} |
| 22 |
|
| 23 |
static auto MakeUniquePtr() { return std::make_unique<std::vector<int>>(); } |
| 24 |
|
| 25 |
void testCopyElidedUniquePtr() { |
| 26 |
[uniquePtr = MakeUniquePtr()] {}(); |
| 27 |
clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 28 |
} |