diff --git a/doc/hotspot-style.html b/doc/hotspot-style.html index 98d813242a5..fb4cffc9d43 100644 --- a/doc/hotspot-style.html +++ b/doc/hotspot-style.html @@ -75,6 +75,9 @@ Standard Library Deduction
auto may
be used as a placeholder for the type of a non-type template parameter.
The type is deduced from the value provided in a template
instantiation.
-Function return type deduction (
+ * Function return type
+deduction (n3638)
Only
use if the function body has a very small number of return
-statements, and generally relatively little other code.
Class template argument deduction (
+
+
The template arguments
of a class template may be deduced from the arguments to a constructor.
@@ -736,7 +742,7 @@ harder to understand, because explicit type information is lacking. But
it can also remove the need to be explicit about types that are either
obvious, or that are very hard to write. For example, these allow the
addition of a scope-guard mechanism with nice syntax; something like
-this
ScopeGuard guard{[&]{ ... cleanup code ... }};
A function's return type may be specified after the parameters and
+qualifiers (n2541).
+In such a declaration the normal return type is auto and
+the return type is indicated by -> followed by the type.
+Although both use auto in the "normal" leading return type
+position, this differs from function return type
+deduction, in that the return type is explicit rather than deduced,
+but specified in a trailing position.
Use of trailing return types is permitted. However, the normal, +leading position for the return type is preferred. A trailing return +type should only be used where it provides some benefit. Such benefits +usually arise because a trailing return type is in a different scope +than a leading return type.
+If the function identifier is a nested name specifier, then the +trailing return type occurs in the nested scope. This may permit simpler +naming in the return type because of the different name lookup +context.
The trailing return type is in the scope of the parameters,
+making their types accessible via decltype. For
+example
template<typename T, typename U> auto add(T t, U u) -> decltype(t + u);
+rather than
+template<typename T, typename U> decltype((*(T*)0) + (*(U*)0)) add(T t, U u);
+C++17 extended the arguments permitted for non-type template
diff --git a/doc/hotspot-style.md b/doc/hotspot-style.md
index e3ba4b470ce..3fd5468d531 100644
--- a/doc/hotspot-style.md
+++ b/doc/hotspot-style.md
@@ -642,6 +642,7 @@ use can make code much harder to understand.
parameter. The type is deduced from the value provided in a template
instantiation.
+
* Function return type deduction
([n3638](https://isocpp.org/files/papers/N3638.html))
Only use if the function body has a very small number of `return`
@@ -691,6 +692,42 @@ Here are a few closely related example bugs: