1*87d0aedaSPiotr Zegar // RUN: %check_clang_tidy -std=c++11-or-later %s readability-reference-to-constructed-temporary %t
2*87d0aedaSPiotr Zegar
3*87d0aedaSPiotr Zegar struct WithConstructor
4*87d0aedaSPiotr Zegar {
5*87d0aedaSPiotr Zegar WithConstructor(int, int);
6*87d0aedaSPiotr Zegar };
7*87d0aedaSPiotr Zegar
8*87d0aedaSPiotr Zegar struct WithoutConstructor
9*87d0aedaSPiotr Zegar {
10*87d0aedaSPiotr Zegar int a, b;
11*87d0aedaSPiotr Zegar };
12*87d0aedaSPiotr Zegar
test()13*87d0aedaSPiotr Zegar void test()
14*87d0aedaSPiotr Zegar {
15*87d0aedaSPiotr Zegar // CHECK-MESSAGES: :[[@LINE+1]]:27: warning: reference variable 'tmp1' extends the lifetime of a just-constructed temporary object 'const WithConstructor', consider changing reference to value [readability-reference-to-constructed-temporary]
16*87d0aedaSPiotr Zegar const WithConstructor& tmp1{1,2};
17*87d0aedaSPiotr Zegar
18*87d0aedaSPiotr Zegar // CHECK-MESSAGES: :[[@LINE+1]]:30: warning: reference variable 'tmp2' extends the lifetime of a just-constructed temporary object 'const WithoutConstructor', consider changing reference to value [readability-reference-to-constructed-temporary]
19*87d0aedaSPiotr Zegar const WithoutConstructor& tmp2{1,2};
20*87d0aedaSPiotr Zegar
21*87d0aedaSPiotr Zegar
22*87d0aedaSPiotr Zegar // CHECK-MESSAGES: :[[@LINE+1]]:22: warning: reference variable 'tmp3' extends the lifetime of a just-constructed temporary object 'WithConstructor', consider changing reference to value [readability-reference-to-constructed-temporary]
23*87d0aedaSPiotr Zegar WithConstructor&& tmp3{1,2};
24*87d0aedaSPiotr Zegar
25*87d0aedaSPiotr Zegar // CHECK-MESSAGES: :[[@LINE+1]]:25: warning: reference variable 'tmp4' extends the lifetime of a just-constructed temporary object 'WithoutConstructor', consider changing reference to value [readability-reference-to-constructed-temporary]
26*87d0aedaSPiotr Zegar WithoutConstructor&& tmp4{1,2};
27*87d0aedaSPiotr Zegar
28*87d0aedaSPiotr Zegar WithConstructor tmp5{1,2};
29*87d0aedaSPiotr Zegar WithoutConstructor tmp6{1,2};
30*87d0aedaSPiotr Zegar }
31