forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc++11.html
1232 lines (1054 loc) · 66.1 KB
/
c++11.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<!--
Copyright 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<html>
<head>
<meta charset="utf-8">
<title>C++11 and C++14 use in Chromium</title>
<link rel="stylesheet" href="c++11.css">
<style>
table tbody tr td:first-child {
font-weight: bold;
font-size: 110%;
}
</style>
</head>
<body>
<div id="content">
<h1>C++11 and C++14 use in Chromium</h1>
<p><i>This document lives at src/styleguide/c++/c++11.html in a Chromium
checkout and is part of the more general
<a href="https://chromium.googlesource.com/chromium/src/+/master/styleguide/c++/c++.md">
Chromium C++ style guide</a>.</i></p>
<p>This summarizes the new and updated features in C++11 and C++14 (for both
the language itself and the Standard Library) from the perspective of what's
allowed in Chromium. When applicable, it contains pointers to more detailed
information. This Guide applies to Chromium and its subprojects, though
subprojects can choose to be more restrictive if necessary for toolchain
support.</p>
<p>You can propose changing the status of a feature by sending an email to
<a href="https://groups.google.com/a/chromium.org/forum/#!forum/cxx">
cxx@chromium.org</a>. Include a short blurb on what the feature is and why you
think it should or should not be allowed, along with links to any relevant
previous discussion. If the list arrives at some consensus, send a codereview to
change this file accordingly, linking to your discussion thread.</p>
<h2>Table of Contents</h2>
<ol class="toc">
<li>Allowed Features<ol>
<li>Language
<a href="#core-whitelist">C++11</a>
<a href="#core-whitelist-14">C++14</a>
</li>
<li>Library
<a href="#library-whitelist">C++11</a>
<a href="#library-whitelist-14">C++14</a>
</li>
</ol></li>
<li>Banned Features<ol>
<li>Language
<a href="#core-blacklist">C++11</a>
<a href="#core-blacklist-14">C++14</a>
</li>
<li>Library
<a href="#library-blacklist">C++11</a>
<a href="#library-blacklist-14">C++14</a>
</li>
</ol></li>
<li>To Be Discussed<ol>
<li>Language
<a href="#core-review">C++11</a>
<a href="#core-review-14">C++14</a>
</li>
<li>Library
<a href="#library-review">C++11</a>
<a href="#library-review-14">C++14</a>
</li>
</ol></li>
</ol>
<h2 id="whitelist"><a name="core-whitelist"></a>C++11 Allowed Features</h2>
<p>The following features are currently allowed.</p>
<table id="whitelist_lang_list" class="unlined striped">
<tbody>
<tr>
<th style='width:220px;'>Feature</th>
<th style='width:260px;'>Snippet</th>
<th style='width:240px;'>Description</th>
<th style='width:240px;'>Documentation Link</th>
<th style='width:240px;'>Notes and Discussion Thread</th>
</tr>
<tr>
<td>__func__ Local Variable</td>
<td><code>__func__</code></td>
<td>Provides a local variable containing the name of the enclosing function</td>
<td><a href="http://en.cppreference.com/w/cpp/language/function#func">__func__</a></td>
<td>Use instead of the non-standard <code>__FUNCTION__</code>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/ojGfcgSDzHM">Discussion thread</a></td>
</tr>
<tr>
<td>Alignment Features</td>
<td><code>alignas(alignof(T)) char[10];</code></td>
<td>Specifies or queries storage alignment.</td>
<td><a href="http://en.cppreference.com/w/chttp://en.cppreference.com/w/cpp/language/alignas">alignas</a>, <a href="http://en.cppreference.com/w/cpp/language/alignof">alignof</a></td>
<td><code>alignof()</code> can be used. <code>alignas()</code> must be used with care because it does not interact well with export and packing specifiers. If your declaration contains any other attributes, use <code>ALIGNAS()</code> from <code>base/compiler_specific.h</code> instead. <a href="https://codereview.chromium.org/2670873002/">Patch where this was discussed</a></td>
</tr>
<tr>
<td>Angle Bracket Parsing in Templates</td>
<td><code>>></code> for <code>> ></code>, <code><::</code> for <code>< ::</code></td>
<td>More intuitive parsing of template parameters</td>
<td><a href="http://stackoverflow.com/questions/15785496/c-templates-angle-brackets-pitfall-what-is-the-c11-fix">C++ templates angle brackets pitfall</a></td>
<td>Recommended to increase readability. Approved without discussion.</td>
</tr>
<tr>
<td>Arrays</td>
<td><code>std::array</code></td>
<td>A fixed-size replacement for built-in arrays, with STL support</td>
<td><a href="http://en.cppreference.com/w/cpp/container/array">std::array</a></td>
<td>Useful in performance-critical situations, with small, fixed-size arrays. In most cases, consider std::vector instead. std::vector is cheaper to std::move and is more widely used. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/pVRQCRWHEU8">Discussion thread</a></td>
</tr>
<tr>
<td>Automatic Types</td>
<td><code>auto</code></td>
<td>Automatic type deduction</td>
<td><a href="http://en.cppreference.com/w/cpp/language/auto">auto specifier</a></td>
<td>General guidance in <a href="https://google.github.io/styleguide/cppguide.html#auto">Google Style Guide</a>. Additionally, do not use <code>auto</code> to deduce a raw pointer, use <code>auto*</code> instead. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/OQyYSfH9m2M">Discussion thread</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/5-Bt3BJzAo0">Another discussion thread</a></td>
</tr>
<tr>
<td>Constant Expressions</td>
<td><code>constexpr</code></td>
<td>Compile-time constant expressions</td>
<td><a href="http://en.cppreference.com/w/cpp/language/constexpr">constexpr specifier</a></td>
<td>Prefer to <code>const</code> for variables where possible. Use cautiously on functions. Don't go out of the way to convert existing code. <a href="https://google.github.io/styleguide/cppguide.html#Use_of_constexpr">Google Style Guide</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/BE9xLUI-Vww">Discussion thread</a></td>
</tr>
<tr>
<td>Declared Type Accessor</td>
<td><code>decltype(<i>expression</i>)</code></td>
<td>Provides a means to determine the type of an expression at compile-time, useful most often in templates.</td>
<td><a href="http://en.cppreference.com/w/cpp/language/decltype">decltype specifier</a></td>
<td>Usage should be rare. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/_zoNvZd_dSo">Discussion thread</a></td>
</tr>
<tr>
<td>Default Function Creation</td>
<td><code><i>Function</i>(<i>arguments</i>) = default;</code></td>
<td>Instructs the compiler to generate a default version of the indicated function</td>
<td><a href="http://stackoverflow.com/questions/823935/whats-the-point-in-defaulting-functions-in-c11">What's the point in defaulting functions in C++11?</a></td>
<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/qgU4mh_MpGA">Discussion thread</a></td>
</tr>
<tr>
<td>Default Function Template Arguments</td>
<td><code>template <typename T = <i>type</i>><br />
<i>type</i> <i>Function</i>(T <i>var</i>) {}</code></td>
<td>Allow function templates, like classes, to have default arguments</td>
<td><a href="http://stackoverflow.com/questions/2447458/default-template-arguments-for-function-templates">Default Template Arguments for Function Templates</a></td>
<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/9KtaAsome-o">Discussion thread</a></td>
</tr>
<tr>
<td>Delegated Constructors</td>
<td><code>Class() : Class(0) {}<br />
Class(<i>type</i> <i>var</i>) : Class(<i>var</i>, 0) {}</code></td>
<td>Allow overloaded constructors to use common initialization code</td>
<td><a href="https://www.ibm.com/developerworks/community/blogs/5894415f-be62-4bc0-81c5-3956e82276f3/entry/introduction_to_the_c_11_feature_delegating_constructors?lang=en">Introduction to the C++11 feature: delegating constructors</a></td>
<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/0zVA8Ctx3Xo">Discussion thread</a></td>
</tr>
<tr>
<td>Enumerated Type Classes and Enum Bases</td>
<td><code>enum class <i>classname</i><br />
enum class <i>classname</i> : <i>base-type</i><br />
enum <i>enumname</i> : <i>base-type</i></code></td>
<td>Provide enums as full classes, with no implicit conversion to booleans or integers. Provide an explicit underlying type for enum classes and regular enums.</td>
<td><a href="http://en.cppreference.com/w/cpp/language/enum">enumeration declaration</a></td>
<td>Enum classes are still enums and follow enum naming rules. <a href="https://google.github.io/styleguide/cppguide.html#Enumerator_Names">Google Style Guide</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/Q5WmkAImanc">Discussion thread</a></td>
</tr>
<tr>
<td>Explicit Conversion Operators</td>
<td><code>explicit operator <i>type</i>() { ... }</code></td>
<td>Allows conversion operators that cannot be implicitly invoked</td>
<td><a href="http://en.cppreference.com/w/cpp/language/explicit">explicit specifier</a></td>
<td>Prefer to the "safe bool" idiom. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/zGF1SrQ-1HQ">Discussion thread</a></td>
</tr>
<tr>
<td>Final Specifier</td>
<td><code>final</code></td>
<td> Indicates that a class or function is final and cannot be overridden</td>
<td><a href="http://en.cppreference.com/w/cpp/language/final">final specifier</a></td>
<td>Recommended for new code. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/VTNZzizN0zo">Discussion thread</a></td>
</tr>
<tr>
<td>Function Suppression</td>
<td><code><i>Function</i>(<i>arguments</i>) = delete;</code></td>
<td>Suppresses the implementation of a function, especially a synthetic function such as a copy constructor</td>
<td><a href="http://en.cppreference.com/w/cpp/language/function#Deleted_functions">Deleted functions</a></td>
<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/i1o7-RNRnMs">Discussion thread</a></td>
</tr>
<tr>
<td>Inherited Constructors</td>
<td><code>class Derived : Base {<br />
using Base::Base;<br />
};</code></td>
<td>Allows derived classes to inherit constructors from base classes</td>
<td><a href="http://en.cppreference.com/w/cpp/language/using_declaration#Inheriting_constructors">Inheriting constructors</a></td>
<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/BULzgIKZ-Ao">Discussion thread</a></td>
</tr>
<tr>
<td>Lambda Expressions</td>
<td><code>[<i>captures</i>](<i>params</i>) -> <i>ret</i> { <i>body</i> }</code></td>
<td>Anonymous functions</td>
<td><a href="http://en.cppreference.com/w/cpp/language/lambda">Lambda functions</a></td>
<td>Lambdas are typically useful as a parameter to methods or functions that will use them immediately, such as those in <code><algorithm></code>. Be careful with default captures (<code>[=]</code>, <code>[&]</code>), and do not bind or store any capturing lambdas outside the lifetime of the stack frame they are defined in; use <code>base::Callback</code> for this instead, as it helps prevent object lifetime mistakes. (Captureless lambdas can be used with <code>base::Bind</code> as they do not have the same risks.) <a href="https://google.github.io/styleguide/cppguide.html#Lambda_expressions">Google Style Guide</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/D9UnnxBnciQ">Discussion thread</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/QxjsPELDYdQ">Another discussion thread</a> (about captureless lambdas and <code>base::Bind</code>).</td>
</tr>
<tr>
<td>Local Types as Template Arguments</td>
<td><code>void func() {<br />
class Pred {<br />
public:<br />
bool operator()(const T&) { ... }<br />
};<br />
std::remove_if(vec.begin(), vec.end(), Pred());</code></td>
<td>Allows local and unnamed types as template arguments</td>
<td><a href="http://stackoverflow.com/questions/742607/using-local-classes-with-stl-algorithms">Local types, types without linkage and unnamed types as template arguments</a></td>
<td>Usage should be rare. Approved without discussion.</td>
</tr>
<tr>
<td>Noexcept Specifier</td>
<td><code>void f() noexcept</code></td>
<td>Specifies that a function will not throw exceptions</td>
<td><a href="http://en.cppreference.com/w/cpp/language/noexcept_spec">noexcept specifier</a></td>
<td>Chromium compiles without exception support, but there are still cases where explicitly marking a function as <code>noexcept</code> may be necessary to compile, or for performance reasons. Use noexcept for move constructors whenever possible (see "Notes" section on <a href="http://en.cppreference.com/w/cpp/language/move_constructor">move constructors</a>). Other usage should be rare. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/8i4tMqNpHhg">Discussion thread</a></td>
</tr>
<tr>
<td>Non-Static Class Member Initializers</td>
<td><code>class C {<br />
<i>type</i> <i>var</i> = <i>value</i>;<br />
C() // copy-initializes <i>var</i></code>
<td>Allows non-static class members to be initialized at their definitions (outside constructors)</td>
<td><a href="http://en.cppreference.com/w/cpp/language/data_members">Non-static data members</a></td>
<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/zqB-DySA4V0">Discussion thread</a></td>
</tr>
<tr>
<td>Null Pointer Constant</td>
<td><code>nullptr</code></td>
<td>Declares a type-safe null pointer</td>
<td><a href="http://en.cppreference.com/w/cpp/language/nullptr">nullptr, the pointer literal</a></td>
<td>Prefer over <code>NULL</code> or <code>0</code>. <a href="https://google.github.io/styleguide/cppguide.html#0_and_nullptr/NULL">Google Style Guide</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/4mijeJHzxLg">Discussion thread</a></td>
</tr>
<tr>
<td>Override Specifier</td>
<td><code>override</code></td>
<td>Indicates that a class or function overrides a base implementation</td>
<td><a href="http://en.cppreference.com/w/cpp/language/override">override specifier</a></td>
<td>Recommended for new code. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/VTNZzizN0zo">Discussion thread</a></td>
</tr>
<tr>
<td>Range-Based For Loops</td>
<td><code>for (<i>type</i> <i>var</i> : <i>range</i>)</code></td>
<td>Facilitates a more concise syntax for iterating over the elements of a container (or a range of iterators) in a <code>for</code> loop</td>
<td><a href="http://en.cppreference.com/w/cpp/language/range-for">Range-based for loop</a></td>
<td>As a rule of thumb, use <code>for (const auto& ...)</code>, <code>for (auto& ...)</code>, or <code>for (<i>concrete type</i> ...)</code>. For pointers, use <code>for (auto* ...)</code> to make clear that the copy of the loop variable is intended, and only a pointer is copied. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/hpzz4EqbVmc">Discussion thread</a></td>
</tr>
<tr>
<td>Raw String Literals</td>
<td><code>string <i>var</i>=R"(<i>raw_string</i>)";</code></td>
<td>Allows a string to be encoded without any escape sequences, easing parsing in regex expressions, for example</td>
<td><a href="http://en.cppreference.com/w/cpp/language/string_literal">string literal</a></td>
<td>Beware of passing these as macro arguments, which can trigger a <a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57824">lexer bug</a> on older GCC versions. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/2kWQHbbuMHI">Discussion thread</a></td>
</tr>
<tr>
<td>Rvalue References</td>
<td><code>T(T&& t)</code> and <code>T& operator=(T&& t)<br/><br/>
template <typename T><br/>void Function(T&& t) { ... }</code></td>
<td>Reference that only binds to a temporary object</td>
<td><a href="http://en.cppreference.com/w/cpp/language/reference#Rvalue_references">Rvalue references</a></td>
<td>Only use these to define move constructors and move assignment operators, and for perfect forwarding. Most classes should not be copyable, even if movable. Continue to use DISALLOW_COPY_AND_ASSIGN in most cases. <a href="https://google.github.io/styleguide/cppguide.html#Rvalue_references">Google Style Guide</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/UnRaORb4TSw">Discussion thread</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/Q526tkruXpM">Another discussion thread</a></td>
</tr>
<tr>
<td>Standard Integers</td>
<td>Typedefs within <code><stdint.h></code> and <code><inttypes></code></td>
<td>Provides fixed-size integers independent of platforms</td>
<td><a href="http://en.cppreference.com/w/cpp/header/cstdint">Standard library header <cstdint></a></td>
<td>Approved without discussion. Required by the <a href="http://google.github.io/styleguide/cppguide.html#Integer_Types">Google Style Guide</a>.</td>
</tr>
<tr>
<td>Static Assertions</td>
<td><code>static_assert(<i>bool</i>, <i>string</i>)</code></td>
<td>Tests compile-time conditions</td>
<td><a href="http://en.cppreference.com/w/cpp/language/static_assert">Static Assertion</a></td>
<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/POISBQEhGzU">Discussion thread</a></td>
</tr>
<tr>
<td>Trailing Return Types</td>
<td><code>auto <i>function declaration</i> -> <i>return_type</i></code></td>
<td>Allows trailing function return value syntax</td>
<td><a href="http://en.cppreference.com/w/cpp/language/function">Declaring functions</a></td>
<td>Use only where it considerably improves readability. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/OQyYSfH9m2M">Discussion thread</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/Lkp0nubVd0Q">Another discussion thread</a></td>
</tr>
<tr>
<td>Type Aliases ("using" instead of "typedef")</td>
<td><code>using <i>new_alias</i> = <i>typename</i></code></td>
<td>Allows parameterized typedefs</td>
<td><a href="http://en.cppreference.com/w/cpp/language/type_alias">Type alias, alias template</a></td>
<td>Use instead of typedef, unless the header needs to be compatible with C. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/8dOAMzgR4ao">Discussion thread</a></td>
</tr>
<tr>
<td>Uniform Initialization Syntax</td>
<td><code><i>type</i> <i>name</i> {[<i>value</i> ..., <i>value</i>]};</code></td>
<td>Allows any object of primitive, aggregate or class type to be initialized using brace syntax</td>
<td><a href="http://www.stroustrup.com/C++11FAQ.html#uniform-init">Uniform initialization syntax and semantics</a></td>
<td>See the <a href="https://www.chromium.org/developers/coding-style/cpp-dos-and-donts?pli=1#TOC-Variable-initialization">Chromium C++ Dos And Don'ts guidance</a> on when to use this. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/GF96FshwHLw">Discussion thread</a></td>
</tr>
<tr>
<td>Union Class Members</td>
<td><code>union <i>name</i> {<i>class</i> <i>var</i>}</code></td>
<td>Allows class type members</td>
<td><a href="http://en.cppreference.com/w/cpp/language/union">Union declaration</a></td>
<td>Usage should be rare. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/3oK78s1ntgU">Discussion thread</a></td>
</tr>
<tr>
<td>Variadic Macros</td>
<td><code>#define <i>MACRO</i>(...) <i>Impl</i>(<i>args</i>, __VA_ARGS__)</code></td>
<td>Allows macros that accept a variable number of arguments</td>
<td><a href="http://stackoverflow.com/questions/4786649/are-variadic-macros-nonstandard">Are Variadic macros nonstandard?</a></td>
<td>Usage should be rare. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/sRx9j3CQqyA">Discussion thread</a></td>
</tr>
<tr>
<td>Variadic Templates</td>
<td><code>template <<i>typename</i> ... <i>arg</i>></code></td>
<td>Allows templates that accept a variable number of arguments</td>
<td><a href="http://en.cppreference.com/w/cpp/language/parameter_pack">Parameter pack</a></td>
<td>Usage should be rare. Use instead of .pump files. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/6ItymeMXpMc">Discussion thread</a></td>
</tr>
</tbody>
</table>
<h2 id="whitelist"><a name="core-whitelist-14"></a>C++14 Allowed Features</h2>
<p>The following features are currently allowed.</p>
<table id="whitelist_lang_list_14" class="unlined striped">
<tbody>
<tr>
<th style='width:220px;'>Feature</th>
<th style='width:260px;'>Snippet</th>
<th style='width:240px;'>Description</th>
<th style='width:240px;'>Documentation Link</th>
<th style='width:240px;'>Notes and Discussion Thread</th>
</tr>
<tr>
<td>Aggregate member initialization</td>
<td><code>struct Point { int x, y, z = 0; };<br>Point p = {2, 3};</code></td>
<td>Allows classes with default member initializers to be initialized with aggregate initialization, optionally omitting data members with such initializers.</td>
<td><a href="http://en.cppreference.com/w/cpp/language/aggregate_initialization">aggregate initialization</a></td>
<td><a href="https://groups.google.com/a/chromium.org/d/topic/cxx/WMBs3K9OQ_E/discussion">Discussion thread</a></td>
</tr>
<tr>
<td>Binary literals</td>
<td><code>int i = 0b1001;</code></td>
<td>Allows defining literals in base two.</td>
<td><a href="http://en.cppreference.com/w/cpp/language/integer_literal">Integer literals</a></td>
<td><a href="https://groups.google.com/a/chromium.org/d/topic/cxx/zsGhgaKLmIk/discussion">Discussion thread</a></td>
</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>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>
<td>Generic lambdas</td>
<td><code>[](const auto& x) { <i>...</i> }</code></td>
<td>Allows lambda argument types to be deduced using <code>auto</code> (according to the rules that apply to templates).</td>
<td><a href="http://en.cppreference.com/w/cpp/language/lambda">lambda expressions</a></td>
<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> int result = 1;<br> while (n > 0)<br> result *= n--;<br> return result;<br>}</code></td>
<td>Allows use of more declarations, conditional statements and loops inside <code>constexpr</code> functions.</td>
<td><a href="http://en.cppreference.com/w/cpp/language/constexpr">constexpr specifier</a></td>
<td>Prefer to <code>const</code> for variables where possible. Use cautiously on functions. Don't go out of the way to convert existing code. <a href="https://google.github.io/styleguide/cppguide.html#Use_of_constexpr">Google Style Guide</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/Psuq_EKJBAo">Discussion thread</a></td>
</tr>
</tbody>
</table>
<h2 id="whitelist"><a name="library-whitelist"></a>C++11 Allowed Library Features</h2>
<p>The following library features are currently allowed.</p>
<table id="whitelist_lib_list" class="unlined striped">
<tbody>
<tr>
<th style='width:240px;'>Feature or Library</th>
<th style='width:240px;'>Snippet</th>
<th style='width:240px;'>Description</th>
<th style='width:240px;'>Documentation Link</th>
<th style='width:240px;'>Notes and Discussion Thread</th>
</tr>
<tr>
<td>Access to underlying <code>std::vector</code> data</td>
<td><code>v.data()</code></td>
<td>Returns a pointer to a <code>std::vector</code>'s underlying data, accounting for empty vectors.</td>
<td><a href="http://en.cppreference.com/w/cpp/container/vector/data">std::vector::data</a></td>
<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/16V7fmtbzok">Discussion thread</a></td>
</tr>
<tr>
<td>Algorithms</td>
<td>All C++11 features in <code><algorithm></code>:<br/>
<code>all_of</code>, <code>any_of</code>, <code>none_of</code><br/>
<code>find_if_not</code><br/>
<code>copy_if</code>, <code>copy_n</code><br/>
<code>move</code>, <code>move_backward</code> (see note)<br/>
<code>shuffle</code><br/>
<code>is_partitioned</code>, <code>partition_copy</code>, <code>partition_point</code><br/>
<code>is_sorted</code>, <code>is_sorted_until</code><br/>
<code>is_heap</code>, <code>is_heap_until</code><br/>
<code>minmax</code>, <code>minmax_element</code><br/>
<code>is_permutation<br/></td>
<td>Safe and performant implementations of common algorithms</td>
<td><a href="http://en.cppreference.com/w/cpp/header/algorithm">Standard library header <algorithm></a></td>
<td>Note that <algorithm> contains a range-based <code>move</code> method. This is allowed, but because people may confuse it with the single-arg <code>std::move</code>, there is often a way to write code without it that is more readable. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/UJQk8S1IuHk">Discussion thread</a>. <a href='https://groups.google.com/a/chromium.org/forum/#!topic/cxx/8WzmtYrZvQ8'>Another discussion thread</a></td>
</tr>
<tr>
<td>Atomics</td>
<td><code><atomic></code></td>
<td>Fine-grained atomic types and operations</td>
<td><a href="http://en.cppreference.com/w/cpp/atomic">Atomic operations library</a></td>
<td>Direct use should be rare because the semantics are subtle. Prefer to use higher-level abstractions built on top of atomics or synchronization primitives.</td>
</tr>
<tr>
<td>Begin and End Non-Member Functions</td>
<td><code>std::begin()</code>, <code>std::end()</code></td>
<td>Allows use of free functions on any container, including fixed-size arrays</td>
<td><a href="http://en.cppreference.com/w/cpp/iterator/begin">std::begin</a>, <a href="http://en.cppreference.com/w/cpp/iterator/end">std::end</a></td>
<td>Useful for fixed-size arrays. Note that non-member <code>cbegin()</code> and <code>cend()</code> are not available until C++14. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/5iFNE8P5qT4">Discussion thread</a></td>
</tr>
<tr>
<td>Conditional Type Selection</td>
<td><code>std::enable_if</code>, <code>std::conditional</code></td>
<td>Enables compile-time conditional type selection</td>
<td><a href="http://en.cppreference.com/w/cpp/types/enable_if">std::enable_if</a>, <a href="http://en.cppreference.com/w/cpp/types/conditional">conditional</a></td>
<td>Usage should be rare. <a href='https://groups.google.com/a/chromium.org/forum/#!topic/cxx/vCxo4tZNd_M'>Discussion thread</a></td>
</tr>
<tr>
<td>Constant Iterator Methods on Containers</td>
<td>E.g. <code>std::vector::cbegin()</code>, <code>std::vector::cend()</code></td>
<td>Allows more widespread use of <code>const_iterator</code></td>
<td><a href="http://en.cppreference.com/w/cpp/container/vector/begin">std::vector::cbegin</a>, <a href="http://en.cppreference.com/w/cpp/container/vector/end">std::vector::cend<a></td>
<td>Applies to all containers, not just <code>vector</code>. Consider using <code>const_iterator</code> over <code>iterator</code> where possible for the same reason as using <code>const</code> variables and functions where possible; see Effective Modern C++ item 13. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/cS83F_buqLM">Discussion thread</a></td>
</tr>
<tr>
<td>Container Compaction Functions</td>
<td><code>std::vector::shrink_to_fit()</code>, <code>std::deque::shrink_to_fit()</code>, <code>std::string::shrink_to_fit()</code></td>
<td>Requests the removal of unused space in the container</td>
<td><a href="http://en.cppreference.com/w/cpp/container/vector/shrink_to_fit">std::vector::shrink_to_fit</a>, <a href="http://en.cppreference.com/w/cpp/container/deque/shrink_to_fit">std::deque::shrink_to_fit</a>, <a href="http://en.cppreference.com/w/cpp/string/basic_string/shrink_to_fit">std::basic_string::shrink_to_fit</a></td>
<td></td>
</tr>
<tr>
<td>Declared Type As Value</td>
<td><code>std::declval<<i>class</i>>()</code></td>
<td>Converts a type to a reference of the type to allow use of members of the type without constructing it in templates.</td>
<td><a href="http://en.cppreference.com/w/cpp/utility/declval">std::declval</a></td>
<td>Usage should be rare. <a href="https://groups.google.com/a/chromium.org/d/topic/cxx/ku6lYjk0-OU/discussion">Discussion thread</a></td>
</tr>
<tr>
<td>Emplacement methods for containers</td>
<td><code>emplace()</code>, <code>emplace_back()</code>, <code>emplace_front()</code>, <code>emplace_hint()</code></td>
<td>Constructs elements directly within a container without a copy or a move. Less verbose than <code>push_back()</code> due to not naming the type being constructed.</td>
<td>E.g. <a href="http://en.cppreference.com/w/cpp/container/vector/emplace_back">std::vector::emplace_back</a></td>
<td>When using emplacement for performance reasons, your type should probably be movable (since e.g. a vector of it might be resized); given a movable type, then, consider whether you really need to avoid the move done by <code>push_back()</code>. For readability concerns, treat like <code>auto</code>; sometimes the brevity over <code>push_back()</code> is a win, sometimes a loss. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/m3cblzEta7A">Discussion thread</a></td>
</tr>
<tr>
<td>Forwarding references</td>
<td><code>std::forward()</code></td>
<td>Perfectly forwards arguments (including rvalues)</td>
<td><a href="http://en.cppreference.com/w/cpp/utility/forward">std::forward</a></td>
<td>Allowed, though usage should be rare (primarily for forwarding constructor arguments, or in carefully reviewed library code). <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/-O7euklhSxs">Discussion thread</a>
</td>
</tr>
<tr>
<td>Initializer Lists</td>
<td><code>std::initializer_list<T></code></td>
<td>Allows containers to be initialized with aggregate elements</td>
<td><a href="http://en.cppreference.com/w/cpp/utility/initializer_list">std::initializer_list</a></td>
<td>Be cautious adding new constructors which take these, as they can hide non-initializer_list constructors in undesirable ways; see Effective Modern C++ Item 7. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/TQQ-L51_naM">Discussion thread</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/UpiCpuu9UNc">Another discussion thread</a></td>
</tr>
<tr>
<td>Iterator Operators</td>
<td><code>std::next()</code>, <code>std::prev()</code></td>
<td>Copies an iterator and increments or decrements the copy by some value</td>
<td><a href="http://en.cppreference.com/w/cpp/iterator/next">std::next</a>, <a href="http://en.cppreference.com/w/cpp/iterator/prev">std::prev</a></td>
<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/KeHhLI-E2Ww">Discussion thread</a></td>
</tr>
<tr>
<td>Math functions</td>
<td>All C++11 features in <code><cmath></code>, e.g.:<br/>
<code>INFINITY</code>, <code>NAN</code>, <code>FP_NAN</code><br/>
<code>float_t</code>, <code>double_t</code><br/>
<code>fmax</code>, <code>fmin</code>, <code>trunc</code>, <code>round</code><br/>
<code>isinf</code>, <code>isnan</code><br/></td>
<td>Useful for math-related code</td>
<td><a href="http://en.cppreference.com/w/cpp/header/cmath">Standard library header <cmath></a></td>
<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/P-1bFBXMeUk">Discussion thread</a></td>
</tr>
<tr>
<td>Move Iterator Adaptor</td>
<td><code>std::make_move_iterator()</code></td>
<td>Wraps an iterator so that it moves objects instead of copying them.</td>
<td><a href="http://en.cppreference.com/w/cpp/iterator/make_move_iterator">std::make_move_iterator</a></td>
<td>Useful to move objects between containers that contain move-only types like <code>std::unique_ptr</code>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/lccnUljOHQU">Discussion thread</a></td>
</tr>
<tr>
<td>Move Semantics</td>
<td><code>std::move()</code></td>
<td>Facilitates efficient move operations</td>
<td><a href="http://en.cppreference.com/w/cpp/utility/move">std::move</a></td>
<td><a href='https://groups.google.com/a/chromium.org/forum/#!topic/cxx/x_dWFxJFdbM'>Discussion thread</a></td>
</tr>
<tr>
<td>Null Pointer Type</td>
<td><code>std::nullptr_t</code></td>
<td>Allows referencing the type of <code>nullptr</code>, e.g. in templates</td>
<td><a href="http://en.cppreference.com/w/cpp/types/nullptr_t">std::nullptr_t</a></td>
<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/UNaXc8R7eJ0">Discussion thread</a></td>
</tr>
<tr>
<td>Random Number Generators</td>
<td><code><random></code></td>
<td>Random number generation algorithms and utilities</td>
<td><a href="http://en.cppreference.com/w/cpp/numeric/random">Pseudo-random number generation</a></td>
<td>Because the standard does not define precisely how the <code><i>xxx</i>_distribution</code> objects generate output, the same object may produce different output for the same seed across platforms, or even across different versions of the STL. Do not use these objects in any scenario where behavioral consistency is required. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/MLgK9vCE4BA">Discussion thread</a></td>
</tr>
<tr>
<td>String Direct Reference Functions</td>
<td><code>std::string::front()</code>, <code>std::string::back()</code></td>
<td>Returns a reference to the front or back of a string</td>
<td><a href="http://en.cppreference.com/w/cpp/string/basic_string/front">std::basic_string::front</a>, <a href="http://en.cppreference.com/w/cpp/string/basic_string/back">std::basic_string::back</a></td>
<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/DRJuROAYCV4">Discussion thread</a></td>
</tr>
<tr>
<td>Type Traits</td>
<td>All C++11 features in <code><type_traits></code> except for aligned storage (see separate item), e.g.:<br/>
<code>integral_constant</code><br/>
<code>is_floating_point</code>, <code>is_rvalue_reference</code>, <code>is_scalar</code><br/>
<code>is_const</code>, <code>is_pod</code>, <code>is_unsigned</code><br/>
<code>is_default_constructible</code>, <code>is_move_constructible</code>, <code>is_copy_assignable</code><br/>
<code>enable_if</code>, <code>conditional</code>, <code>result_of</code><br/></td>
<td>Allows compile-time inspection of the properties of types</td>
<td><a href="http://en.cppreference.com/w/cpp/header/type_traits">Standard library header <type_traits></a></td>
<td><a href='https://groups.google.com/a/chromium.org/forum/#!topic/cxx/vCxo4tZNd_M'>Discussion thread</a></td>
</tr>
<tr>
<td>Tuples</td>
<td>All C++11 features in <code><tuple></code>, e.g. <code>std::tie</code> and <code>std::tuple</code>.</td>
<td>A fixed-size ordered collection of values of mixed types</td>
<td><a href="http://en.cppreference.com/w/cpp/header/tuple">Standard library header <tuple></a></td>
<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/0NnCRmMY1xY">Discussion thread</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/VA7Ej2IWS2w">Another discussion thread</a></td>
</tr>
<tr>
<td>Unordered Associative Containers</td>
<td><code>std::unordered_set</code>, <code>std::unordered_map</code>, <code>std::unordered_multiset</code>, <code>std::unordered_multimap</code></td>
<td>Allows efficient containers of key/value pairs</td>
<td><a href="http://en.cppreference.com/w/cpp/container/unordered_map">std::unordered_map</a>, <a href="http://en.cppreference.com/w/cpp/container/unordered_set">std::unordered_set</a></td>
<td>Specify custom hashers instead of specializing <code>std::hash</code> for custom types. <a href="https://google.github.io/styleguide/cppguide.html#std_hash">Google Style Guide</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/nCdjQqnouO4">Discussion thread</a></td>
</tr>
<tr>
<td>Unique Pointers</td>
<td><code>std::unique_ptr<<i>type</i>></code></td>
<td>A smart pointer with sole ownership of the owned object.</td>
<td><a href="http://en.cppreference.com/w/cpp/memory/unique_ptr">std::unique_ptr</a></td>
<td><a href="https://google.github.io/styleguide/cppguide.html#Ownership_and_Smart_Pointers">Google Style Guide</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/aT2wsBLKvzI">Discussion thread</a></td>
</tr>
</tbody>
</table>
<h2 id="whitelist"><a name="library-whitelist-14"></a>C++14 Allowed Library Features</h2>
<p>The following library features are currently allowed.</p>
<table id="whitelist_lib_list" class="unlined striped">
<tbody>
<tr>
<th style='width:240px;'>Feature or Library</th>
<th style='width:240px;'>Snippet</th>
<th style='width:240px;'>Description</th>
<th style='width:240px;'>Documentation Link</th>
<th style='width:240px;'>Notes and Discussion Thread</th>
</tr>
<tr>
<td>Constant begin/end non-member functions</td>
<td><code>std::cbegin(<i>container</i>)<br>std::cend(<i>container</i>)<br>std::crbegin(<i>container</i>)<br>std::crend(<i>container</i>)</br></code></td>
<td>Constant counterparts to <code>std::begin</code> etc.</td>
<td><a href="http://en.cppreference.com/w/cpp/iterator/begin">std::cbegin</a></td>
<td></td>
</tr>
<tr>
<td>Heterogeneous lookup in associative containers</td>
<td><code><i>// Does not construct an std::string to use as the lookup key.</i><br>std::map<std::string, int, std::less<>> map;<br>auto it = map.find("answer");</code></td>
<td>Allows searching associative containers without converting the key to exactly match the stored key type, assuming a suitable comparator exists.</td>
<td><a href="http://en.cppreference.com/w/cpp/utility/functional/less">std::less</a></td>
<td><a href="https://groups.google.com/a/chromium.org/d/msg/cxx/ow7hmdDm4yw/EDEvBRi_BQAJ">Discussion thread</a></td>
</tr>
<tr>
<td><code>std::integer_sequence</code></td>
<td><code>template <size_t... I><br>void CallFooImpl(std::index_sequence<I...>) {<br> Foo(I...);<br>}<br><br>template <size_t N><br>void CallFoo() {<br> CallFooImpl(std::make_index_sequence<N>());<br>}</code></td>
<td>Template metaprogramming utility for representing a sequence of integers as a type.</td>
<td><a href="http://en.cppreference.com/w/cpp/utility/integer_sequence">std::integer_sequence</a></td>
<td>This also includes the alias, <code>std::index_sequence</code>, which is the specialization for <code>size_t</code>. <a href="https://groups.google.com/a/chromium.org/d/msg/cxx/ow7hmdDm4yw/EDEvBRi_BQAJ">Discussion thread</a></td>
</tr>
<tr>
<td><code>std::make_unique</code></td>
<td><code>auto widget = std::make_unique<Widget>();</code></td>
<td>Allocates objects on the heap and immediately constructs an <code>std::unique_ptr</code> to assume ownership.</td>
<td><a href="http://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique">std::make_unique</a></td>
<td>Should replace <code>base::MakeUnique</code> and <code>WTF::MakeUnique</code>. <a href="https://groups.google.com/a/chromium.org/d/msg/cxx/ow7hmdDm4yw/EDEvBRi_BQAJ">Discussion thread</a></td>
</tr>
<tr>
<td>Transparent function objects</td>
<td>Arithmetic operations:<br><code>std::plus<>, std::minus<></code> ...<br>Comparisons:<br><code>std::less<>, std::equal_to<></code>...<br>Logical operations:<br><code>std::logical_and<>, std::logical_or<></code>...<br>Bitwise operations:<br><code>std::bit_and<>, std::bit_or<></code>...<br></td>
<td>Function objects that deduce argument types.</td>
<td><a href="http://en.cppreference.com/w/cpp/utility/functional/less_void">std::less<></a></td>
<td>Should replace <code>base::less</code> and usage of these functors with explicit types where appropriate. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/cPoULd2NY9k">Discussion thread</a></td>
</tr>
<tr>
<td>Tuple addressing by type</td>
<td><code>std::tuple<int, char> enterprise(1701, 'D');<br>int n = std::get<int>(enterprise);</code></td>
<td>Allows entries in a tuple to be accessed by type rather than entry, if it is not ambiguous.</td>
<td><a href="http://en.cppreference.com/w/cpp/utility/tuple/get">std::get(std::tuple)</a></td>
<td></td>
</tr>
<tr>
<td>Reverse Iterator Adaptor</td>
<td><code>std::make_reverse_iterator()</code></td>
<td>For a given iterator, deduces the type of a corresponding reverse iterator and constructs it.</td>
<td><a href="http://en.cppreference.com/w/cpp/iterator/make_reverse_iterator">std::make_reverse_iterator</a></td>
<td>Useful to reduce boilerplate when constructing reverse iterators. The alternative is using <code>std::reverse_iterator<T>(i)</code> where <code>T</code> is the, usually long, type of the iterator <code>i</code>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/qOE1XA0b6Dk">Discussion thread</a></td>
</tr>
</tbody>
</table>
<h2 id="blacklist">C++11 and C++14 Blacklist (Disallowed and Banned Features)</h2>
<p>This section lists features that are not allowed to be used yet.
<h3 id="blacklist_banned"><a name="core-blacklist"></a>C++11 Banned Features</h3>
<p>This section lists C++11 features that are not allowed in the Chromium codebase.</p>
<table id="banned_list" class="unlined striped">
<tbody>
<tr>
<th style='width:240px;'>Feature or Library</th>
<th style='width:240px;'>Snippet</th>
<th style='width:240px;'>Description</th>
<th style='width:240px;'>Documentation Link</th>
<th style='width:240px;'>Notes and Discussion Thread</th>
</tr>
<tr>
<td>Inline Namespaces</td>
<td><code>inline namespace foo { ... }</code></td>
<td>Allows better versioning of namespaces</td>
<td><a href="http://en.cppreference.com/w/cpp/language/namespace#Inline_namespaces">Inline namespaces</a></td>
<td>Banned in the <a href="https://google.github.io/styleguide/cppguide.html#Namespaces">Google Style Guide</a>. Unclear how it will work with components.</td>
</tr>
<tr>
<td><code>long long</code> Type</td>
<td><code>long long <i>var</i> = <i>value</i>;</code></td>
<td>An integer of at least 64 bits</td>
<td><a href="http://en.cppreference.com/w/cpp/language/types">Fundamental types</a></td>
<td>Use a stdint.h type if you need a 64bit number. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/RxugZ-pIDxk">Discussion thread</a></td>
</tr>
<tr>
<td>Ref-qualified Member Functions</td>
<td><code>class T {<br />
void f() & {}<br />
void f() && {}<br />
};<br />
t.f(); // first<br />
T().f(); // second<br />
std::move(t).f(); // second</code></td>
<td>Allows class member functions to only bind to |this| as an rvalue or lvalue.</td>
<td><a href="http://en.cppreference.com/w/cpp/language/member_functions#const-.2C_volatile-.2C_and_ref-qualified_member_functions">const-, volatile-, and ref-qualified member functions</a></td>
<td>Banned in the <a href="https://google.github.io/styleguide/cppguide.html#C++11">Google Style Guide</a>. May only be used in Chromium with explicit approval from <code>styleguide/c++/OWNERS</code>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/gowclr2LPQA">Discussion Thread</a></td>
</tr>
<tr>
<td>User-Defined Literals</td>
<td><code><i>type</i> <i>var</i> = <i>literal_value</i>_<i>type</i></code></td>
<td>Allows user-defined literal expressions</td>
<td><a href="http://en.cppreference.com/w/cpp/language/user_literal">User-defined literals</a></td>
<td>Banned in the <a href="https://google.github.io/styleguide/cppguide.html#Operator_Overloading">Google Style Guide</a>.</td>
</tr>
<tr>
<td>thread_local storage class</td>
<td><code>thread_local int foo = 1;</code></td>
<td>Puts variables into thread local storage.</td>
<td><a href="http://en.cppreference.com/w/cpp/language/storage_duration">Storage duration</a></td>
<td>Some surprising effects on Mac (<a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/2msN8k3Xzgs">discussion</a>, <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/h7O5BdtWCZw">fork</a>). Use <a href="https://cs.chromium.org/chromium/src/base/threading/sequence_local_storage_slot.h">SequenceLocalStorageSlot</a> for sequence support, and <a href="https://cs.chromium.org/chromium/src/base/threading/thread_local.h">ThreadLocal</a>/<a href="https://cs.chromium.org/chromium/src/base/threading/thread_local_storage.h">ThreadLocalStorage</a> otherwise.</td>
</tr>
</tbody>
</table>
<h3 id="blacklist_banned"><a name="core-blacklist-14"></a>C++14 Banned Features</h3>
<p>This section lists C++14 features that are not allowed in the Chromium codebase.</p>
<table id="banned_list" class="unlined striped">
<tbody>
<tr>
<th style='width:240px;'>Feature</th>
<th style='width:240px;'>Snippet</th>
<th style='width:240px;'>Description</th>
<th style='width:240px;'>Documentation Link</th>
<th style='width:240px;'>Notes and Discussion Thread</th>
</tr>
<tr>
</tbody>
</table>
<h3 id="blacklist_stdlib"><a name="library-blacklist"></a>C++11 Banned Library Features</h3>
<p>This section lists C++11 library features that are not allowed in the Chromium codebase.</p>
<table id="blacklist_lib_list" class="unlined striped">
<tbody>
<tr>
<th style='width:240px;'>Feature</th>
<th style='width:240px;'>Snippet</th>
<th style='width:240px;'>Description</th>
<th style='width:240px;'>Documentation Link</th>
<th style='width:240px;'>Notes and Discussion Thread</th>
</tr>
<tr>
<td>Aligned storage</td>
<td><code>std::aligned_storage<10, 128></code></td>
<td>Uninitialized storage for objects requiring specific alignment.</td>
<td><a href="http://en.cppreference.com/w/cpp/types/aligned_storage">std::aligned_storage</a></td>
<td>MSVC 2017's implementation does not align on boundaries greater than sizeof(double) = 8 bytes. Use <code>alignas(128) char foo[10];</code> instead. <a href="https://codereview.chromium.org/2932053002">Patch where this was discovered</a>.</td>
</tr>
<td>Bind Operations</td>
<td><code>std::bind(<i>function</i>, <i>args</i>, ...)</code></td>
<td>Declares a function object bound to certain arguments</td>
<td><a href="http://en.cppreference.com/w/cpp/utility/functional/bind">std::bind</a></td>
<td>Use <code>base::Bind</code> instead. Compared to <code>std::bind</code>, <code>base::Bind</code> helps prevent lifetime issues by preventing binding of capturing lambdas and by forcing callers to declare raw pointers as <code>Unretained</code>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/SoEj7oIDNuA">Discussion thread</a></td>
</tr>
<tr>
<td>C Floating-Point Environment</td>
<td><code><cfenv></code>, <code><fenv.h></code></td>
<td>Provides floating point status flags and control modes for C-compatible code</td>
<td><a href="http://en.cppreference.com/w/cpp/header/cfenv">Standard library header <cfenv></a></td>
<td>Banned by the <a href="https://google.github.io/styleguide/cppguide.html#C++11">Google Style Guide</a> due to concerns about compiler support.</td>
</tr>
<tr>
<td>Date and time utilities</td>
<td><code><chrono></code></td>
<td>A standard date and time library</td>
<td><a href="http://en.cppreference.com/w/cpp/chrono">Date and time utilities</a></td>
<td>Overlaps with <code>Time</code> APIs in <code>base/</code>. Keep using the <code>base/</code> classes.</td>
</tr>
<tr>
<td>Exceptions</td>
<td><code><exception></code></td>
<td>Enhancements to exception throwing and handling</td>
<td><a href="http://en.cppreference.com/w/cpp/header/exception">Standard library header <exception></a></td>
<td>Exceptions are banned by the <a href="https://google.github.io/styleguide/cppguide.html#Exceptions">Google Style Guide</a> and disabled in Chromium compiles. Note that the <code>noexcept</code> specifier is explicitly allowed above. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/8i4tMqNpHhg">Discussion thread</a></td>
</tr>
<tr>
<td>Function Objects</td>
<td><code>std::function</code></td>
<td>Wraps a standard polymorphic function</td>
<td><a href="http://en.cppreference.com/w/cpp/utility/functional/function">std::function</a></td>
<td>Use <code>base::Callback</code> instead. Compared to <code>std::function</code>, <code>base::Callback</code> directly supports Chromium's refcounting classes and weak pointers and deals with additional thread safety concerns. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/SoEj7oIDNuA">Discussion thread</a></td>
</tr>
<tr>
<td>Ratio Template Class</td>
<td><code>std::ratio<<i>numerator</i>, <i>denominator</i>></code></td>
<td>Provides compile-time rational numbers</td>
<td><a href="http://en.cppreference.com/w/cpp/numeric/ratio/ratio">std::ratio</a></td>
<td>Banned by the <a href="https://google.github.io/styleguide/cppguide.html#C++11">Google Style Guide</a> due to concerns that this is tied to a more template-heavy interface style.</td>
</tr>
<tr>
<td>Regular Expressions</td>
<td><code><regex></code></td>
<td>A standard regular expressions library</td>
<td><a href="http://en.cppreference.com/w/cpp/regex">Regular expressions library</a></td>
<td>Overlaps with many regular expression libraries in Chromium. When in doubt, use re2.</td>
</tr>
<tr>
<td>Shared Pointers</td>
<td><code>std::shared_ptr</code></td>
<td>Allows shared ownership of a pointer through reference counts</td>
<td><a href="http://en.cppreference.com/w/cpp/memory/shared_ptr">std::shared_ptr</a></td>
<td>Needs a lot more evaluation for Chromium, and there isn't enough of a push for this feature. <a href="https://google.github.io/styleguide/cppguide.html#Ownership_and_Smart_Pointers">Google Style Guide</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/aT2wsBLKvzI">Discussion Thread</a></td>
</tr>
<tr>
<td>Thread Library</td>
<td><code><thread></code> and related headers, including<br />
<code><future></code>, <code><mutex></code>, <code><condition_variable></code></td>
<td>Provides a standard multithreading library using <code>std::thread</code> and associates</td>
<td><a href="http://en.cppreference.com/w/cpp/thread">Thread support library</a></td>
<td>Overlaps with many classes in <code>base/</code>. Keep using the <code>base/</code> classes for now. <code>base::Thread</code> is tightly coupled to <code>MessageLoop</code> which would make it hard to replace. We should investigate using standard mutexes, or unique_lock, etc. to replace our locking/synchronization classes.</td>
</tr>
</tbody>
</table>
<h3 id="blacklist_stdlib"><a name="library-blacklist-14"></a>C++14 Banned Library Features</h3>
<p>This section lists C++14 library features that are not allowed in the Chromium codebase.</p>
<table id="blacklist_lib_list" class="unlined striped">
<tbody>
<tr>
<th style='width:240px;'>Feature</th>
<th style='width:240px;'>Snippet</th>
<th style='width:240px;'>Description</th>
<th style='width:240px;'>Documentation Link</th>
<th style='width:240px;'>Notes and Discussion Thread</th>
</tr>
<tr>
<td><code>std::chrono</code> literals</td>
<td><code>using namespace std::chrono_literals;<br>auto timeout = 30s;</code></td>
<td>Allows <code>std::chrono</code> types to be more easily constructed.</td>
<td><a href="http://en.cppreference.com/w/cpp/chrono/operator%22%22s">std::literals::chrono_literals::operator""s</a></td>
<td>Banned because <code><chrono></code> is banned.</td>
</tr>
</tbody>
</table>
<h3 id="blacklist_review"><a name="core-review"></a>C++11 Features To Be Discussed</h3>
<p>The following C++ language features are currently disallowed. See the top of this page on how to propose moving a feature from this list into the allowed or banned sections.</p>
<table id="blacklist_review_list" class="unlined striped">
<tbody>
<tr>
<th style='width:240px;'>Feature</th>
<th style='width:240px;'>Snippet</th>
<th style='width:240px;'>Description</th>
<th style='width:240px;'>Documentation Link</th>
<th style='width:240px;'>Notes and Discussion Thread</th>
</tr>
<tr>
<td>Attributes</td>
<td><code>[[<i>attribute_name</i>]]</code></td>
<td>Attaches properties to declarations that specific compiler implementations may use.</td>
<td><a href="http://www.codesynthesis.com/~boris/blog/2012/04/18/cxx11-generalized-attributes/">C++11 generalized attributes</a></td>
<td></td>
</tr>
<tr>
<td>UTF-8, UTF-16, UTF-32 String Literals</td>
<td><code>u8"<i>string</i>", u"<i>string</i>", U"<i>string</i>"</code></td>
<td>Enforces UTF-8, UTF-16, UTF-32 encoding on all string literals</td>
<td><a href="http://en.cppreference.com/w/cpp/language/string_literal">string literal</a></td>
<td>Reevaluate now that MSVS2015 is available. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/gcoUbcjfsII">Discussion thread</a></td>
</tr>
<tr>
<td>UTF-16 and UTF-32 Support (16-Bit and 32-Bit Character Types)</td>
<td><code>char16_t</code> and <code>char32_t</code></td>
<td>Provides character types for handling 16-bit and 32-bit code units (useful for encoding UTF-16 and UTF-32 string data)</td>
<td><a href="http://en.cppreference.com/w/cpp/language/types">Fundamental types</a></td>
<td>Reevaluate now that MSVS2015 is available. Non-UTF-8 text is banned by the <a href="https://google.github.io/styleguide/cppguide.html#Non-ASCII_Characters">Google Style Guide</a>. However, may be useful for consuming non-ASCII data. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/ME2kL7_Kvyk">Discussion thread</a></td>
</tr>
</tbody>
</table>
<h3 id="blacklist_review"><a name="core-review-14"></a>C++14 Features To Be Discussed</h3>
<p>The following C++14 language features are currently disallowed. See the top of this page on how to propose moving a feature from this list into the allowed or banned sections.</p>
<table id="blacklist_review_list" class="unlined striped">
<tbody>
<tr>
<th style='width:240px;'>Feature</th>
<th style='width:240px;'>Snippet</th>
<th style='width:240px;'>Description</th>
<th style='width:240px;'>Documentation Link</th>
<th style='width:240px;'>Notes and Discussion Thread</th>
</tr>
<tr>
<td><code>[[deprecated]]</code> attribute</td>
<td><code>[[deprecated]] void f();<br>
[[deprecated("use h() instead")]] void g();</code></td>
<td>Marks a function as deprecated.</td>
<td><a href="http://en.cppreference.com/w/cpp/language/attributes">Standard attributes</a></td>
<td>We don't use deprecation warnings in Chromium; if you want to deprecate
something, remove all callers and remove the function instead.</td>
</tr>
<tr>
<td><code>decltype(auto)</code> variable declarations</td>
<td><code>decltype(auto) x = 42;</code></td>
<td>Allows deducing the type of a variable using <code>decltype</code> rules.</td>
<td><a href="http://en.cppreference.com/w/cpp/language/auto">auto specifier</a></td>