diff options
author | Jason Merrill <jason@redhat.com> | 2023-06-06 12:46:26 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2023-06-06 21:32:23 -0400 |
commit | 2ae5384d457b9c67586de012816dfc71a6943164 (patch) | |
tree | 698566d6d43131fc80aa5eface85144a5ef14056 /gcc/doc | |
parent | 7e0b65b239c3a0d68ce94896b236b03de666ffd6 (diff) | |
download | gcc-2ae5384d457b9c67586de012816dfc71a6943164.zip gcc-2ae5384d457b9c67586de012816dfc71a6943164.tar.gz gcc-2ae5384d457b9c67586de012816dfc71a6943164.tar.bz2 |
c++: Add -Wnrvo
While looking at PRs about cases where we don't perform the named return
value optimization, it occurred to me that it might be useful to have a
warning for that.
This does not fix PR58487, but might be interesting to people watching it.
PR c++/58487
gcc/c-family/ChangeLog:
* c.opt: Add -Wnrvo.
gcc/ChangeLog:
* doc/invoke.texi: Document it.
gcc/cp/ChangeLog:
* typeck.cc (want_nrvo_p): New.
(check_return_expr): Handle -Wnrvo.
gcc/testsuite/ChangeLog:
* g++.dg/opt/nrv25.C: New test.
Diffstat (limited to 'gcc/doc')
-rw-r--r-- | gcc/doc/invoke.texi | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 9130104..6d08229 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -6678,6 +6678,25 @@ is only active when @option{-fdelete-null-pointer-checks} is active, which is enabled by optimizations in most targets. The precision of the warnings depends on the optimization options used. +@opindex Wnrvo +@opindex Wno-nrvo +@item -Wnrvo @r{(C++ and Objective-C++ only)} +Warn if the compiler does not elide the copy from a local variable to +the return value of a function in a context where it is allowed by +[class.copy.elision]. This elision is commonly known as the Named +Return Value Optimization. For instance, in the example below the +compiler cannot elide copies from both v1 and b2, so it elides neither. + +@smallexample +std::vector<int> f() +@{ + std::vector<int> v1, v2; + // ... + if (cond) return v1; + else return v2; // warning: not eliding copy +@} +@end smallexample + @opindex Winfinite-recursion @opindex Wno-infinite-recursion @item -Winfinite-recursion |