diff options
author | peter klausler <pklausler@nvidia.com> | 2018-07-25 15:13:40 -0700 |
---|---|---|
committer | peter klausler <pklausler@nvidia.com> | 2018-08-03 16:23:57 -0700 |
commit | 439ddb334f2da162fe465aaeb45b670eb5e3ef13 (patch) | |
tree | 8575f72fb10c2bbfa6eb89673057b455713190bb /flang/documentation | |
parent | b861018e3a1bda307b8ebe6724eb144e74e3aba6 (diff) | |
download | llvm-439ddb334f2da162fe465aaeb45b670eb5e3ef13.tar.gz |
[flang] Use std::nullopt in place of empty braces in return statements.
Original-commit: flang-compiler/f18@90e556301c47c953e13900974dd5175d07bcc8ad
Reviewed-on: https://github.com/flang-compiler/f18/pull/162
Tree-same-pre-rewrite: false
Diffstat (limited to 'flang/documentation')
-rw-r--r-- | flang/documentation/C++style.md | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/flang/documentation/C++style.md b/flang/documentation/C++style.md index 2b6cef20fc2a..6bdac9549c77 100644 --- a/flang/documentation/C++style.md +++ b/flang/documentation/C++style.md @@ -102,11 +102,14 @@ you are considering. 1. Never use run-time type information or `dynamic_cast<>`. 1. Never declare static data that executes a constructor. (This is why `#include <iostream>` is contraindicated.) -Use `{braced initializers}` in all circumstances where they work, including +1. Use `{braced initializers}` in all circumstances where they work, including default data member initialization. They inhibit implicit truncation. Don't use `= expr` initialization just to effect implicit truncation; prefer an explicit `static_cast<>`. With C++17, braced initializers work fine with `auto` too. +Sometimes, however, there are better alternatives to empty braces; +e.g., prefer `return std::nullopt;` to `return {};` to make it more clear +that the function's result type is a `std::optional<>`. 1. Avoid unsigned types apart from `size_t`, which must be used with care. When `int` just obviously works, just use `int`. When you need something bigger than `int`, use `std::int64_t` rather than `long` or `long long`. @@ -133,7 +136,8 @@ explicitly, it should contains either a `default:;` at its end or a `default:` label that obviously crashes. #### Classes 1. Define POD structures with `struct`. -1. Don't use `this->` in (non-static) member functions. +1. Don't use `this->` in (non-static) member functions, unless forced to +do so in a template. 1. Define accessor and mutator member functions (implicitly) inline in the class, after constructors and assignments. Don't needlessly define (implicit) inline member functions in classes unless they really solve a |