Skip to content

Commit

Permalink
Allow return type deduction per discussion thread.
Browse files Browse the repository at this point in the history
BUG=none
TEST=none

Change-Id: I7bf9deba405fa33397c48d6f9e8e3340646c95a4
Reviewed-on: https://chromium-review.googlesource.com/855818
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547369}
  • Loading branch information
pkasting authored and Commit Bot committed Mar 31, 2018
1 parent 322fd32 commit c2f8749
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion base/bind_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ template <typename T>
using Unwrapper = BindUnwrapTraits<std::decay_t<T>>;

template <typename T>
auto Unwrap(T&& o) -> decltype(Unwrapper<T>::Unwrap(std::forward<T>(o))) {
decltype(auto) Unwrap(T&& o) {
return Unwrapper<T>::Unwrap(std::forward<T>(o));
}

Expand Down
3 changes: 1 addition & 2 deletions base/test/bind_test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ struct BindLambdaHelper<F, R(Args...)> {
// A variant of Bind() that can bind capturing lambdas for testing.
// This doesn't support extra arguments binding as the lambda itself can do.
template <typename F>
RepeatingCallback<internal::ExtractCallableRunType<std::decay_t<F>>>
BindLambdaForTesting(F&& f) {
decltype(auto) BindLambdaForTesting(F&& f) {
using Signature = internal::ExtractCallableRunType<std::decay_t<F>>;
return BindRepeating(&internal::BindLambdaHelper<F, Signature>::Run,
std::forward<F>(f));
Expand Down
27 changes: 14 additions & 13 deletions styleguide/c++/c++11.html
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,11 @@ <h2 id="whitelist"><a name="core-whitelist-14"></a>C++14 Allowed Features</h2>
</tr>

<tr>
<td>Number literal separators</td>
<td><code>float f = 1'000'000.000'1;</code></td>
<td><code>'</code>s anywhere in int or float literals are ignored</td>
<td><a href="http://en.cppreference.com/w/cpp/language/integer_literal">Integer literals</a>, <a href="http://en.cppreference.com/w/cpp/language/floating_literal">Floating point literals</a></td>
<td><a href="https://groups.google.com/a/chromium.org/d/topic/cxx/exS1aGs1wes/discussion">Discussion thread</a></td>
<td>Function return type deduction</td>
<td><code>auto f() { return 42; }<br>decltype(auto) g() { return 42; }</code></td>
<td>Allows the return type of a function to be automatically deduced from its return statements, according to either template or <code>decltype</code> rules.</td>
<td><a href="http://en.cppreference.com/w/cpp/language/function#Return_type_deduction">Return type deduction</a></td>
<td>Usage should be rare, primarily for abstract template code. If you're not sure of the difference, prefer decltype(auto) for templated forwarding/wrapper functions and auto for other cases; see Effective Modern C++ item 3 for more detail. <a href="https://groups.google.com/a/chromium.org/d/topic/cxx/-Ox7YgRS_no/discussion">Discussion thread</a></td>
</tr>

<tr>
Expand All @@ -408,6 +408,14 @@ <h2 id="whitelist"><a name="core-whitelist-14"></a>C++14 Allowed Features</h2>
<td><a href="https://groups.google.com/a/chromium.org/d/topic/cxx/LasGKwE3SFM/discussion">Discussion thread</a></td>
</tr>

<tr>
<td>Number literal separators</td>
<td><code>float f = 1'000'000.000'1;</code></td>
<td><code>'</code>s anywhere in int or float literals are ignored</td>
<td><a href="http://en.cppreference.com/w/cpp/language/integer_literal">Integer literals</a>, <a href="http://en.cppreference.com/w/cpp/language/floating_literal">Floating point literals</a></td>
<td><a href="https://groups.google.com/a/chromium.org/d/topic/cxx/exS1aGs1wes/discussion">Discussion thread</a></td>
</tr>

<tr>
<td>Relaxed constant expressions</td>
<td><code>constexpr int Factorial(int n) {<br>&nbsp;&nbsp;int result = 1;<br>&nbsp;&nbsp;while (n > 0)<br>&nbsp;&nbsp;&nbsp;&nbsp;result *= n--;<br>&nbsp;&nbsp;return result;<br>}</code></td>
Expand Down Expand Up @@ -783,13 +791,6 @@ <h3 id="blacklist_banned"><a name="core-blacklist-14"></a>C++14 Banned Features<
</tr>

<tr>
<td>Function return type deduction</td>
<td><code>auto f() { return 42; }<br>decltype(auto) g() { return 42; }</code></td>
<td>Allows the return type of a function to be automatically deduced from its return statements, according to either template or <code>decltype</code> rules.</td>
<td><a href="http://en.cppreference.com/w/cpp/language/function#Return_type_deduction">Return type deduction</a></td>
<td>Temporarily banned since it <a href="https://bugs.llvm.org/show_bug.cgi?id=34185">can cause infinite loops in clang</a>. We expect to allow this once that bug is fixed. Usage should be rare, primarily for abstract template code. <a href="https://groups.google.com/a/chromium.org/d/topic/cxx/-Ox7YgRS_no/discussion">Discussion thread</a></td>
</tr>

</tbody>
</table>

Expand Down Expand Up @@ -1067,7 +1068,7 @@ <h3 id="blacklist_stdlib_review"><a name="library-review"></a>C++11 Standard Lib
</tr>

<tr>
<td>Function Return Type Deduction</td>
<td>Function Return Type Extraction</td>
<td><code>std::result_of&lt;<i>Functor(ArgTypes...)</i>&gt;</code></td>
<td>Extracts the return type from the type signature of a function call invocation at compile-time.</td>
<td><a href="http://en.cppreference.com/w/cpp/types/result_of">std::result_of</a></td>
Expand Down

0 comments on commit c2f8749

Please sign in to comment.