diff options
author | tstellar <tstellar@91177308-0d34-0410-b5e6-96231b3b80d8> | 2012-09-24 15:51:24 +0000 |
---|---|---|
committer | tstellar <tstellar@91177308-0d34-0410-b5e6-96231b3b80d8> | 2012-09-24 15:51:24 +0000 |
commit | 5530caeb598491c0de400f01d0b578686031234c (patch) | |
tree | ac9c40c4274a462a065043eb3c2285c20a5eb088 /docs | |
parent | bf4b6ef7caabf1235918bff1bbe583ba651ccb5b (diff) |
Document "do not use defaults in covered switch-over-enum" coding standard.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/R600/@164493 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'docs')
-rw-r--r-- | docs/CodingStandards.rst | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/docs/CodingStandards.rst b/docs/CodingStandards.rst index 4f955e3012b..ecd5626eb0d 100644 --- a/docs/CodingStandards.rst +++ b/docs/CodingStandards.rst @@ -818,6 +818,24 @@ 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. +Don't use default labels in fully covered switches over enumerations +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +``-Wswitch`` warns if a switch, without a default label, over an enumeration +does not cover every enumeration value. If you write a default label on a fully +covered switch over an enumeration then the ``-Wswitch`` warning won't fire +when new elements are added to that enumeration. To help avoid adding these +kinds of defaults, Clang has the warning ``-Wcovered-switch-default`` which is +off by default but turned on when building LLVM with a version of Clang that +supports the warning. + +A knock-on effect of this stylistic requirement is that when building LLVM with +GCC you may get warnings related "control may reach end of non-void function" +if you return from each case of a covered switch-over-enum because GCC assumes +that the enum expression may take any representable value, not just those in +the enumeration. To suppress this warning, use ``llvm_unreachable`` after the +switch. + Use ``LLVM_DELETED_FUNCTION`` to mark uncallable methods ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |