Issue 177747
Summary -Wnrvo has annoying false positives with lifetimes and inside templates
Labels new issue
Assignees
Reporter higher-performance
    ```
template<class T>
auto foo(T v) {
	if constexpr (sizeof(v) > 0) {
		struct {} a;
		return a;
	} else {
		return 0;
	}
}

int main() {
	foo(0);
}
```
[produces](https://godbolt.org/z/vEModM9Pq):
```
<source>:5:10: warning: not eliding copy on return [-Wnrvo]
    5 |                 return a;
      |                        ^
<source>:12:2: note: in instantiation of function template specialization 'foo<int>' requested here
   12 | foo(0);
      |         ^
```

It appears as if the check naively looks for multiple `return` statements inside the template, completely missing two key facts:

1. The different parts of the template are not instantiated simultaneously.
1. The lifetimes of the possible return values do not overlap.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to