Files
TheRock/compiler/amd-llvm/clang/test/SemaCXX/warn-nrvo.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

74 lines
1.9 KiB
C++

// RUN: %clang_cc1 -fsyntax-only -Wnrvo -Wno-return-mismatch -verify %s
struct MyClass {
int value;
int c;
MyClass(int v) : value(v), c(0) {}
MyClass(const MyClass& other) : value(other.value) { c++; }
};
MyClass create_object(bool condition) {
MyClass obj1(1);
MyClass obj2(2);
if (condition) {
return obj1; // expected-warning{{not eliding copy on return}}
}
return obj2; // expected-warning{{not eliding copy on return}}
}
MyClass create_object2(){
MyClass obj(1);
return obj; // no warning
}
template<typename T>
T create_object3(){
T obj(1);
return obj; // no warning
}
// Known issue: if a function template uses a
// deduced return type (i.e. auto or decltype(auto)),
// then NRVO is not applied for any instantiation of
// that function template
// (see https://github.com/llvm/llvm-project/issues/95280).
template<typename T>
auto create_object4(){
T obj(1);
return obj; // expected-warning{{not eliding copy on return}}
}
template<bool F>
MyClass create_object5(){
MyClass obj1(1);
if constexpr (F){
MyClass obj2(2);
return obj2; // no warning
}
// Missed NRVO optimization by clang
return obj1; // expected-warning{{not eliding copy on return}}
}
constexpr bool Flag = false;
MyClass create_object6(){
MyClass obj1(1);
if constexpr (Flag){
MyClass obj2(2);
return obj2; // expected-warning{{not eliding copy on return}}
}
return obj1; // no warning
}
void create_object7(){
if constexpr (Flag){
MyClass obj1(1);
return obj1; // no warning
}
}
void init_templates(){
create_object3<MyClass>(); // no warning
create_object4<MyClass>(); // expected-note {{in instantiation of function template specialization 'create_object4<MyClass>' requested here}}
create_object5<false>(); // expected-note {{in instantiation of function template specialization 'create_object5<false>' requested here}}
}