C++ ObjC++ Var(warn_namespaces) Warning
Warn on namespace definition.
+Wnrvo
+C++ ObjC++ Var(warn_nrvo)
+Warn if the named return value optimization is not performed although it is allowed.
+
Wpacked-not-aligned
C ObjC C++ ObjC++ Var(warn_packed_not_aligned) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall)
Warn when fields in a struct with the packed attribute are misaligned.
&& !TYPE_VOLATILE (TREE_TYPE (retval)));
}
+/* True if we would like to perform NRVO, i.e. can_do_nrvo_p is true and we
+ would otherwise return in memory. */
+
+static bool
+want_nrvo_p (tree retval, tree functype)
+{
+ return (can_do_nrvo_p (retval, functype)
+ && aggregate_value_p (functype, current_function_decl));
+}
+
/* Like can_do_nrvo_p, but we check if we're trying to move a class
prvalue. */
bare_retval = tree_strip_any_location_wrapper (retval);
}
- bool named_return_value_okay_p = can_do_nrvo_p (bare_retval, functype);
+ bool named_return_value_okay_p = want_nrvo_p (bare_retval, functype);
if (fn_returns_value_p && flag_elide_constructors)
{
if (named_return_value_okay_p
|| current_function_return_value == bare_retval))
current_function_return_value = bare_retval;
else
- current_function_return_value = error_mark_node;
+ {
+ if ((named_return_value_okay_p
+ || (current_function_return_value
+ && current_function_return_value != error_mark_node))
+ && !warning_suppressed_p (current_function_decl, OPT_Wnrvo))
+ {
+ warning (OPT_Wnrvo, "not eliding copy on return in %qD",
+ current_function_decl);
+ suppress_warning (current_function_decl, OPT_Wnrvo);
+ }
+ current_function_return_value = error_mark_node;
+ }
}
/* We don't need to do any conversions when there's nothing being
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