Skip to content

Commit 4595137

Browse files
committed
Added tests with dead branches
1 parent 82e3c18 commit 4595137

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

clang/test/SemaCXX/warn-nrvo.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsyntax-only -Wnrvo -verify %s
1+
// RUN: %clang_cc1 -fsyntax-only -Wnrvo -Wno-return-mismatch -verify %s
22
struct MyClass {
33
int value;
44
int c;
@@ -37,7 +37,37 @@ auto create_object4(){
3737
return obj; // expected-warning{{not eliding copy on return}}
3838
}
3939

40+
template<bool F>
41+
MyClass create_object5(){
42+
MyClass obj1(1);
43+
if constexpr (F){
44+
MyClass obj2(2);
45+
return obj2; // no warning
46+
}
47+
// Missed NRVO optimization by clang
48+
return obj1; // expected-warning{{not eliding copy on return}}
49+
}
50+
51+
constexpr bool Flag = false;
52+
53+
MyClass create_object6(){
54+
MyClass obj1(1);
55+
if constexpr (Flag){
56+
MyClass obj2(2);
57+
return obj2; // expected-warning{{not eliding copy on return}}
58+
}
59+
return obj1; // no warning
60+
}
61+
62+
void create_object7(){
63+
if constexpr (Flag){
64+
MyClass obj1(1);
65+
return obj1; // no warning
66+
}
67+
}
68+
4069
void init_templates(){
4170
create_object3<MyClass>(); // no warning
4271
create_object4<MyClass>(); // expected-note {{in instantiation of function template specialization 'create_object4<MyClass>' requested here}}
72+
create_object5<false>(); // expected-note {{in instantiation of function template specialization 'create_object5<false>' requested here}}
4373
}

0 commit comments

Comments
 (0)