diff options
author | Craig Topper <craig.topper@gmail.com> | 2012-09-18 04:43:40 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@gmail.com> | 2012-09-18 04:43:40 +0000 |
commit | 88b5a2bf343120b1cc01685dda4815d2c17c7cd1 (patch) | |
tree | 33bc155ecf3fbc5029a0a3a3f36dc2788188fb40 /docs/CodingStandards.rst | |
parent | cee033188f7b1a4f1b28b8edce0c1358f19f8158 (diff) | |
download | external_llvm-88b5a2bf343120b1cc01685dda4815d2c17c7cd1.zip external_llvm-88b5a2bf343120b1cc01685dda4815d2c17c7cd1.tar.gz external_llvm-88b5a2bf343120b1cc01685dda4815d2c17c7cd1.tar.bz2 |
Add LLVM_DELETED_FUNCTION to coding standards.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164101 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'docs/CodingStandards.rst')
-rw-r--r-- | docs/CodingStandards.rst | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/docs/CodingStandards.rst b/docs/CodingStandards.rst index a416a1e..bc58f57 100644 --- a/docs/CodingStandards.rst +++ b/docs/CodingStandards.rst @@ -818,6 +818,34 @@ least one out-of-line virtual method in the class. Without this, the compiler will copy the vtable and RTTI into every ``.o`` file that ``#include``\s the header, bloating ``.o`` file sizes and increasing link times. +Use ``LLVM_DELETED_FUNCTION`` to mark uncallable methods +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Prior to C++11, a common pattern to make a class uncopyable was to declare an +unimplemented copy constructor and copy assignment operator and make them +private. This would give a compiler error for accessing a private method or a +linker error because it wasn't implemented. + +With C++11, we can mark methods that won't be implemented with ``= deleted``. +This will trigger a much better error message and tell the compiler that the +method will never be implemented. This enables other checks like +``-Wunused-private-field`` to run correctly on classes that contain these +methods. + +To maintain compatibility with C++03, ``LLVM_DELETED_FUNCTION`` should be used +which will expand to ``= deleted`` if the compiler supports it. These methods +should still be declared private. Example of the uncopyable pattern: + +.. code-block:: c++ + + class DontCopy { + private: + DontCopy(const DontCopy&) LLVM_DELETED_FUNCTION; + DontCopy &operator =(const DontCopy&) LLVM_DELETED_FUNCTION; + public: + ... + }; + Don't evaluate ``end()`` every time through a loop ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |