File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change 1- // RUN: %clang_cc1 -fsyntax-only -Wnrvo -verify %s
1+ // RUN: %clang_cc1 -fsyntax-only -Wnrvo -Wno-return-mismatch - verify %s
22struct 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+
4069void 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}
You can’t perform that action at this time.
0 commit comments