From 5684bbc8b5eda7592399f144eda966846117aed9 Mon Sep 17 00:00:00 2001
From: "mark@chromium.org"
Date: Fri, 12 Jul 2013 18:53:13 +0000
Subject: [PATCH] Update C++ style guide to 3.260: - Add boost::bimap to the
list of allowed Boost libraries. - C++11: remove mention of constexpr. -
Remove noun/verb naming rules, and consolidate "General Naming Rules". -
C++11: allow variadic templates. - Revise guidance on function definition
comments. - Clarify that one space is sufficient before trailing /* */
comments. - C++11: allow alias templates. - C++11: allow
-Revision 3.245
+Revision 3.260
Note that gcc implements
@@ -967,6 +973,12 @@ Tashana Landray
exceptions.
Such exceptions should be clearly marked with comments.
+ Finally, constructors that take only an initializer_list may be
+ non-explicit. This is to permit construction of your type using the
+ assigment form for brace init lists (i.e.
- for (int i = 0; i
< 10; ++i) correctly (the scope of i is
@@ -779,8 +787,6 @@ Tashana Landray
Static or global variables of class type are forbidden: they cause
hard-to-find bugs due to indeterminate order of construction and
destruction.
- However, such variables are allowed if they are constexpr:
- they have no dynamic initialization or destruction.
MyType m = {1, 2}
+ ).
+ scoped_ptr
- is great. You should only use std::tr1::shared_ptr
+ If you actually need pointer semantics, unique_ptr
+ is great, and scoped_ptr is fine if you need to support
+ older versions of C++. You should only use shared_ptr
with a non-const referent when it is truly necessary to share ownership
of an object (e.g. inside an STL container). You should never use
auto_ptr.
@@ -1481,11 +1494,15 @@ Tashana Landray
+
unique_ptrscoped_ptrunique_ptr unless C++03 compatibility is
+ required.auto_ptrunique_ptr instead, if possible.shared_ptrshared_ptr<const
@@ -2162,8 +2179,6 @@ Tashana Landray
const whenever it makes sense.
- With C++11,
- constexpr is a better choice for some uses of const.
constexpr
- to define true constants or to ensure constant initialization.
- constexpr
- to indicate the variables are true constants,
- i.e. fixed at compilation/link time.
- Some functions and constructors can be declared constexpr
- which enables them to be used
- in defining a constexpr variable.
- constexpr enables
- definition of constants with floating-point expressions
- rather than just literals;
- definition of constants of user-defined types; and
- definition of constants with function calls.
- constexpr definitions enable a more robust
- specification of the constant parts of an interface.
- Use constexpr to specify true constants
- and the functions that support their definitions.
- Avoid complexifying function definitions to enable
- their use with constexpr.
- Do not use constexpr to force inlining.
-
The interaction between auto and C++11
- brace-initialization can be confusing. (C++11 brace-initialization
- isn't an approved feature, but this may become relevant when and
- if it is permitted.) The declarations
+ brace-initialization can be confusing. The declarations
auto is permitted, for local variables only.
Do not use auto for file-scope or namespace-scope
- variables, or for class members.auto-typed variable.
The auto keyword is also used in an unrelated
C++11 feature: it's part of the syntax for a new kind of
function declaration with a trailing return type. Function
@@ -2766,6 +2735,88 @@ Tashana Landray