Mercurial > hg > CbC > CbC_llvm
comparison docs/CodingStandards.rst @ 120:1172e4bd9c6f
update 4.0.0
author | mir3636 |
---|---|
date | Fri, 25 Nov 2016 19:14:25 +0900 |
parents | afa8332a0e37 |
children | 803732b1fca8 |
comparison
equal
deleted
inserted
replaced
101:34baf5011add | 120:1172e4bd9c6f |
---|---|
81 Supported C++11 Language and Library Features | 81 Supported C++11 Language and Library Features |
82 --------------------------------------------- | 82 --------------------------------------------- |
83 | 83 |
84 While LLVM, Clang, and LLD use C++11, not all features are available in all of | 84 While LLVM, Clang, and LLD use C++11, not all features are available in all of |
85 the toolchains which we support. The set of features supported for use in LLVM | 85 the toolchains which we support. The set of features supported for use in LLVM |
86 is the intersection of those supported in MSVC 2013, GCC 4.7, and Clang 3.1. | 86 is the intersection of those supported in the minimum requirements described |
87 in the :doc:`GettingStarted` page, section `Software`. | |
87 The ultimate definition of this set is what build bots with those respective | 88 The ultimate definition of this set is what build bots with those respective |
88 toolchains accept. Don't argue with the build bots. However, we have some | 89 toolchains accept. Don't argue with the build bots. However, we have some |
89 guidance below to help you know what to expect. | 90 guidance below to help you know what to expect. |
90 | 91 |
91 Each toolchain provides a good reference for what it accepts: | 92 Each toolchain provides a good reference for what it accepts: |
124 * ``override`` and ``final``: N2928_, N3206_, N3272_ | 125 * ``override`` and ``final``: N2928_, N3206_, N3272_ |
125 * Atomic operations and the C++11 memory model: N2429_ | 126 * Atomic operations and the C++11 memory model: N2429_ |
126 * Variadic templates: N2242_ | 127 * Variadic templates: N2242_ |
127 * Explicit conversion operators: N2437_ | 128 * Explicit conversion operators: N2437_ |
128 * Defaulted and deleted functions: N2346_ | 129 * Defaulted and deleted functions: N2346_ |
129 | |
130 * But not defaulted move constructors or move assignment operators, MSVC 2013 | |
131 cannot synthesize them. | |
132 * Initializer lists: N2627_ | 130 * Initializer lists: N2627_ |
133 * Delegating constructors: N1986_ | 131 * Delegating constructors: N1986_ |
134 * Default member initializers (non-static data member initializers): N2756_ | 132 * Default member initializers (non-static data member initializers): N2756_ |
135 | 133 |
136 * Only use these for scalar members that would otherwise be left | 134 * Only use these for scalar members that would otherwise be left |
137 uninitialized. Non-scalar members generally have appropriate default | 135 uninitialized. Non-scalar members generally have appropriate default |
138 constructors, and MSVC 2013 has problems when braced initializer lists are | 136 constructors. |
139 involved. | |
140 | 137 |
141 .. _N2118: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2118.html | 138 .. _N2118: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2118.html |
142 .. _N2439: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2439.htm | 139 .. _N2439: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2439.htm |
143 .. _N1720: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1720.html | 140 .. _N1720: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1720.html |
144 .. _N1984: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1984.pdf | 141 .. _N1984: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1984.pdf |
186 the Linux build bots to find out if your usage triggered a bug. For example, if | 183 the Linux build bots to find out if your usage triggered a bug. For example, if |
187 you hit a type trait which doesn't work we can then add support to LLVM's | 184 you hit a type trait which doesn't work we can then add support to LLVM's |
188 traits header to emulate it. | 185 traits header to emulate it. |
189 | 186 |
190 .. _the libstdc++ manual: | 187 .. _the libstdc++ manual: |
191 http://gcc.gnu.org/onlinedocs/gcc-4.7.3/libstdc++/manual/manual/status.html#status.iso.2011 | 188 http://gcc.gnu.org/onlinedocs/gcc-4.8.0/libstdc++/manual/manual/status.html#status.iso.2011 |
192 | 189 |
193 Other Languages | 190 Other Languages |
194 --------------- | 191 --------------- |
195 | 192 |
196 Any code written in the Go programming language is not subject to the | 193 Any code written in the Go programming language is not subject to the |
265 file is released under. This makes it perfectly clear what terms the source | 262 file is released under. This makes it perfectly clear what terms the source |
266 code can be distributed under and should not be modified in any way. | 263 code can be distributed under and should not be modified in any way. |
267 | 264 |
268 The main body is a ``doxygen`` comment (identified by the ``///`` comment | 265 The main body is a ``doxygen`` comment (identified by the ``///`` comment |
269 marker instead of the usual ``//``) describing the purpose of the file. The | 266 marker instead of the usual ``//``) describing the purpose of the file. The |
270 first sentence or a passage beginning with ``\brief`` is used as an abstract. | 267 first sentence (or a passage beginning with ``\brief``) is used as an abstract. |
271 Any additional information should be separated by a blank line. If an | 268 Any additional information should be separated by a blank line. If an |
272 algorithm is being implemented or something tricky is going on, a reference | 269 algorithm is being implemented or something tricky is going on, a reference |
273 to the paper where it is published should be included, as well as any notes or | 270 to the paper where it is published should be included, as well as any notes or |
274 *gotchas* in the code to watch out for. | 271 *gotchas* in the code to watch out for. |
275 | 272 |
307 #. When writing a header file that may be ``#include``\d by a C source file. | 304 #. When writing a header file that may be ``#include``\d by a C source file. |
308 | 305 |
309 #. When writing a source file that is used by a tool that only accepts C style | 306 #. When writing a source file that is used by a tool that only accepts C style |
310 comments. | 307 comments. |
311 | 308 |
312 To comment out a large block of code, use ``#if 0`` and ``#endif``. These nest | 309 Commenting out large blocks of code is discouraged, but if you really have to do |
313 properly and are better behaved in general than C style comments. | 310 this (for documentation purposes or as a suggestion for debug printing), use |
311 ``#if 0`` and ``#endif``. These nest properly and are better behaved in general | |
312 than C style comments. | |
314 | 313 |
315 Doxygen Use in Documentation Comments | 314 Doxygen Use in Documentation Comments |
316 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 315 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
317 | 316 |
318 Use the ``\file`` command to turn the standard file header into a file-level | 317 Use the ``\file`` command to turn the standard file header into a file-level |
319 comment. | 318 comment. |
320 | 319 |
321 Include descriptive paragraphs for all public interfaces (public classes, | 320 Include descriptive paragraphs for all public interfaces (public classes, |
322 member and non-member functions). Don't just restate the information that can | 321 member and non-member functions). Don't just restate the information that can |
323 be inferred from the API name. The first sentence or a paragraph beginning | 322 be inferred from the API name. The first sentence (or a paragraph beginning |
324 with ``\brief`` is used as an abstract. Put detailed discussion into separate | 323 with ``\brief``) is used as an abstract. Try to use a single sentence as the |
324 ``\brief`` adds visual clutter. Put detailed discussion into separate | |
325 paragraphs. | 325 paragraphs. |
326 | 326 |
327 To refer to parameter names inside a paragraph, use the ``\p name`` command. | 327 To refer to parameter names inside a paragraph, use the ``\p name`` command. |
328 Don't use the ``\arg name`` command since it starts a new paragraph that | 328 Don't use the ``\arg name`` command since it starts a new paragraph that |
329 contains documentation for the parameter. | 329 contains documentation for the parameter. |
347 | 347 |
348 A documentation comment that uses all Doxygen features in a preferred way: | 348 A documentation comment that uses all Doxygen features in a preferred way: |
349 | 349 |
350 .. code-block:: c++ | 350 .. code-block:: c++ |
351 | 351 |
352 /// \brief Does foo and bar. | 352 /// Does foo and bar. |
353 /// | 353 /// |
354 /// Does not do foo the usual way if \p Baz is true. | 354 /// Does not do foo the usual way if \p Baz is true. |
355 /// | 355 /// |
356 /// Typical usage: | 356 /// Typical usage: |
357 /// \code | 357 /// \code |
449 .. _Main Module Header: | 449 .. _Main Module Header: |
450 .. _Local/Private Headers: | 450 .. _Local/Private Headers: |
451 | 451 |
452 #. Main Module Header | 452 #. Main Module Header |
453 #. Local/Private Headers | 453 #. Local/Private Headers |
454 #. ``llvm/...`` | 454 #. LLVM project/subproject headers (``clang/...``, ``lldb/...``, ``llvm/...``, etc) |
455 #. System ``#include``\s | 455 #. System ``#include``\s |
456 | 456 |
457 and each category should be sorted lexicographically by the full path. | 457 and each category should be sorted lexicographically by the full path. |
458 | 458 |
459 The `Main Module Header`_ file applies to ``.cpp`` files which implement an | 459 The `Main Module Header`_ file applies to ``.cpp`` files which implement an |
461 **first** regardless of where it lives on the file system. By including a | 461 **first** regardless of where it lives on the file system. By including a |
462 header file first in the ``.cpp`` files that implement the interfaces, we ensure | 462 header file first in the ``.cpp`` files that implement the interfaces, we ensure |
463 that the header does not have any hidden dependencies which are not explicitly | 463 that the header does not have any hidden dependencies which are not explicitly |
464 ``#include``\d in the header, but should be. It is also a form of documentation | 464 ``#include``\d in the header, but should be. It is also a form of documentation |
465 in the ``.cpp`` file to indicate where the interfaces it implements are defined. | 465 in the ``.cpp`` file to indicate where the interfaces it implements are defined. |
466 | |
467 LLVM project and subproject headers should be grouped from most specific to least | |
468 specific, for the same reasons described above. For example, LLDB depends on | |
469 both clang and LLVM, and clang depends on LLVM. So an LLDB source file should | |
470 include ``lldb`` headers first, followed by ``clang`` headers, followed by | |
471 ``llvm`` headers, to reduce the possibility (for example) of an LLDB header | |
472 accidentally picking up a missing include due to the previous inclusion of that | |
473 header in the main source file or some earlier header file. clang should | |
474 similarly include its own headers before including llvm headers. This rule | |
475 applies to all LLVM subprojects. | |
466 | 476 |
467 .. _fit into 80 columns: | 477 .. _fit into 80 columns: |
468 | 478 |
469 Source Code Width | 479 Source Code Width |
470 ^^^^^^^^^^^^^^^^^ | 480 ^^^^^^^^^^^^^^^^^ |
1154 Factory<Tire> Factory; // Better. | 1164 Factory<Tire> Factory; // Better. |
1155 Factory<Tire> TireFactory; // Even better -- if VehicleMaker has more than one | 1165 Factory<Tire> TireFactory; // Even better -- if VehicleMaker has more than one |
1156 // kind of factories. | 1166 // kind of factories. |
1157 }; | 1167 }; |
1158 | 1168 |
1159 Vehicle MakeVehicle(VehicleType Type) { | 1169 Vehicle makeVehicle(VehicleType Type) { |
1160 VehicleMaker M; // Might be OK if having a short life-span. | 1170 VehicleMaker M; // Might be OK if having a short life-span. |
1161 Tire Tmp1 = M.makeTire(); // Bad -- 'Tmp1' provides no information. | 1171 Tire Tmp1 = M.makeTire(); // Bad -- 'Tmp1' provides no information. |
1162 Light Headlight = M.makeLight("head"); // Good -- descriptive. | 1172 Light Headlight = M.makeLight("head"); // Good -- descriptive. |
1163 ... | 1173 ... |
1164 } | 1174 } |