From 0bb2de37a0005246c2068c8198e9ee2dbb69f6c4 Mon Sep 17 00:00:00 2001 From: hsutter Date: Mon, 13 Mar 2017 11:32:41 -0700 Subject: [PATCH] Closed 856 and 857 Added C++17-specific text in ES.6 for `if` and `switch` initializers. Note that the Guidelines assume C++14, so the "Enforcement" clauses for C++17-specific rules will be separate until we assume people have broad access to C++17 features in their compilers. Once that happens we can roll the C++17-specific parts into the main text. --- CppCoreGuidelines.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 5de7061..73841e2 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -9097,6 +9097,25 @@ Readability. Minimize resource retention. * Flag loop variables declared before the loop and not used after the loop * (hard) Flag loop variables declared before the loop and used after the loop for an unrelated purpose. +##### C++17 example + +Note: C++17 also adds `if` and `switch` initializer statements. These require C++17 support. + + map mymap; + + if (auto result = mymap.insert(value); result.second) { + // insert succeeded, and result is valid for this block + use(result.first); // ok + // ... + } // result is destroyed here + +##### C++17 enforcement (if using a C++17 compiler) + +* Flag selection/loop variables declared before the body and not used after the body +* (hard) Flag selection/loop variables declared before the body and used after the body for an unrelated purpose. + + + ### ES.7: Keep common and local names short, and keep uncommon and nonlocal names longer ##### Reason