summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-03-03 16:48:44 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-03-03 16:48:44 +0000
commit9724e833ce35b0ebf6db8096e5a7cdd65a35660e (patch)
tree6193e1053d8d992930c34fa0fd33561638b629a5 /llvm
parent3efb895bb1cb004455d952e9e7ffdff2d812dd3a (diff)
downloadbcm5719-llvm-9724e833ce35b0ebf6db8096e5a7cdd65a35660e.tar.gz
bcm5719-llvm-9724e833ce35b0ebf6db8096e5a7cdd65a35660e.zip
Clarify struct usage guidelines
The current coding standards restrict the use of struct to PODs, but no one has been following them. This patch updates the standards to clarify when structs are dangerous and describe common practice in LLVM. llvm-svn: 202728
Diffstat (limited to 'llvm')
-rw-r--r--llvm/docs/CodingStandards.rst36
1 files changed, 31 insertions, 5 deletions
diff --git a/llvm/docs/CodingStandards.rst b/llvm/docs/CodingStandards.rst
index de2ac3fbe5f..edf001aeda0 100644
--- a/llvm/docs/CodingStandards.rst
+++ b/llvm/docs/CodingStandards.rst
@@ -650,12 +650,38 @@ members public by default.
Unfortunately, not all compilers follow the rules and some will generate
different symbols based on whether ``class`` or ``struct`` was used to declare
-the symbol. This can lead to problems at link time.
+the symbol (e.g., MSVC). This can lead to problems at link time.
-So, the rule for LLVM is to always use the ``class`` keyword, unless **all**
-members are public and the type is a C++ `POD
-<http://en.wikipedia.org/wiki/Plain_old_data_structure>`_ type, in which case
-``struct`` is allowed.
+* All declarations and definitions of a given ``class`` or ``struct`` must use
+ the same keyword. For example:
+
+.. code-block:: c++
+
+ class Foo;
+
+ // Breaks mangling in MSVC.
+ struct Foo { int Data; };
+
+* As a rule of thumb, ``struct`` should be kept to structures where *all*
+ members are declared public.
+
+.. code-block:: c++
+
+ // Foo feels like a class... this is strange.
+ struct Foo {
+ private:
+ int Data;
+ public:
+ Foo() : Data(0) { }
+ int getData() const { return Data; }
+ void setData(int D) { Data = D; }
+ };
+
+ // Bar isn't POD, but it does look like a struct.
+ struct Bar {
+ int Data;
+ Foo() : Data(0) { }
+ };
Do not use Braced Initializer Lists to Call a Constructor
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OpenPOWER on IntegriCloud