1 // RUN: %check_clang_tidy -std=c++11-or-later %s readability-reference-to-constructed-temporary %t
2
3 struct WithConstructor
4 {
5 WithConstructor(int, int);
6 };
7
8 struct WithoutConstructor
9 {
10 int a, b;
11 };
12
test()13 void test()
14 {
15 // 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 const WithConstructor& tmp1{1,2};
17
18 // 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 const WithoutConstructor& tmp2{1,2};
20
21
22 // 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 WithConstructor&& tmp3{1,2};
24
25 // 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 WithoutConstructor&& tmp4{1,2};
27
28 WithConstructor tmp5{1,2};
29 WithoutConstructor tmp6{1,2};
30 }
31