1 // RUN: %clang_analyze_cc1 -Wno-unused -std=c++11 -analyzer-checker=core,debug.ExprInspection -verify %s
2 // RUN: %clang_analyze_cc1 -Wno-unused -std=c++17 -analyzer-checker=core,debug.ExprInspection -verify %s
3 // RUN: %clang_analyze_cc1 -Wno-unused -std=c++11 -analyzer-checker=core,debug.ExprInspection -DMOVES -verify %s
4 // RUN: %clang_analyze_cc1 -Wno-unused -std=c++17 -analyzer-checker=core,debug.ExprInspection -DMOVES -verify %s
6 void clang_analyzer_eval(bool);
7 void clang_analyzer_checkInlined(bool);
9 template <typename T> struct AddressVector {
13 AddressVector() : len(0) {}
25 C(AddressVector<C> &v) : v(v) { v.push(this); }
26 ~C() { v.push(this); }
29 C(C &&c) : v(c.v) { v.push(this); }
32 // Note how return-statements prefer move-constructors when available.
33 C(const C &c) : v(c.v) {
35 clang_analyzer_checkInlined(false); // no-warning
42 @interface NSObject {}
44 @interface Foo: NSObject {}
45 -(C) make: (AddressVector<C> &)v;
49 -(C) make: (AddressVector<C> &)v {
54 void testReturnByValueFromMessage(Foo *foo) {
57 const C &c = [foo make: v];
59 // 0. Construct the return value of -make (copy/move elided) and
60 // lifetime-extend it directly via reference 'c',
61 // 1. Destroy the temporary lifetime-extended by 'c'.
62 clang_analyzer_eval(v.len == 2); // expected-warning{{TRUE}}
63 clang_analyzer_eval(v.buf[0] == v.buf[1]); // expected-warning{{TRUE}}