Skip to content

Commit 82e3c18

Browse files
committed
Added more tests
1 parent 4b34c65 commit 82e3c18

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

clang/test/SemaCXX/warn-nrvo.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,30 @@ MyClass create_object(bool condition) {
1414
}
1515
return obj2; // expected-warning{{not eliding copy on return}}
1616
}
17+
18+
MyClass create_object2(){
19+
MyClass obj(1);
20+
return obj; // no warning
21+
}
22+
23+
template<typename T>
24+
T create_object3(){
25+
T obj(1);
26+
return obj; // no warning
27+
}
28+
29+
// Known issue: if a function template uses a
30+
// deduced return type (i.e. auto or decltype(auto)),
31+
// then NRVO is not applied for any instantiation of
32+
// that function template
33+
// (see https://github.com/llvm/llvm-project/issues/95280).
34+
template<typename T>
35+
auto create_object4(){
36+
T obj(1);
37+
return obj; // expected-warning{{not eliding copy on return}}
38+
}
39+
40+
void init_templates(){
41+
create_object3<MyClass>(); // no warning
42+
create_object4<MyClass>(); // expected-note {{in instantiation of function template specialization 'create_object4<MyClass>' requested here}}
43+
}

0 commit comments

Comments
 (0)