diff --git a/flang/documentation/C++style.md b/flang/documentation/C++style.md index eb1a4dbedd38..561ae2d1f7cd 100755 --- a/flang/documentation/C++style.md +++ b/flang/documentation/C++style.md @@ -77,6 +77,11 @@ the end of the line, not on the next line. Functions also put the opening `{` after the formal arguments or new-style result type, not on the next line. Use `{}` for empty inline constructors and destructors in classes. +If any branch of an `if`/`else if`/`else` cascade ends with a return statement, +they all should, with the understanding that the cases are all unexceptional. +When testing for an error case that should cause an early return, do so with +an `if` that doesn't have a following `else`. + Don't waste space on the screen with needless blank lines or elaborate block commentary (lines of dashes, boxes of asterisks, &c.). Write code so as to be easily read and understood with a minimum of scrolling. diff --git a/flang/lib/parser/idioms.h b/flang/lib/parser/idioms.h index fe28fa56de6a..d80bdc0a1c4e 100644 --- a/flang/lib/parser/idioms.h +++ b/flang/lib/parser/idioms.h @@ -131,6 +131,7 @@ std::ostream &formatTuple(std::ostream &o, const T &x) { if constexpr (J < std::tuple_size_v) { return formatTuple(o << std::get(x), x); } + return o; } template diff --git a/flang/lib/parser/parse-tree-visitor.h b/flang/lib/parser/parse-tree-visitor.h index 6710b1c353dc..9953a6094759 100644 --- a/flang/lib/parser/parse-tree-visitor.h +++ b/flang/lib/parser/parse-tree-visitor.h @@ -73,11 +73,21 @@ Walk(const A &x, V &visitor) { template typename std::enable_if>::type -Walk(const A &x, V &visitor) { Walk(x.t, visitor); } +Walk(const A &x, V &visitor) { + if (visitor.Pre(x)) { + Walk(x.t, visitor); + visitor.Post(x); + } +} template typename std::enable_if>::type -Walk(const A &x, V &visitor) { Walk(x.u, visitor); } +Walk(const A &x, V &visitor) { + if (visitor.Pre(x)) { + Walk(x.u, visitor); + visitor.Post(x); + } +} template typename std::enable_if>::type