On 1/7/2014, 6:18 PM, Cameron McCormack wrote:
Benjamin Smedberg wrote:
1) Bracing of method bodies in a C++ class declaration

Currently, C++ method bodies inline within a class declaration are
documented to start on the next line, e.g.

class B
{
public:
void Method()
{
// Inline body brace is on the next line, column 2
}
};

Mozilla code widely puts the opening bracde of inline bodies such as
this on the end of the declaration line, and I want to make sure we're
in agreement to fix this.

I don't mind too much.

If we do make it same-line, it would be nice to write down how to handle
empty inline method/constructor bodies, too:

   class A
   {
     A(int aMember)
       : mMember(aMember) {
     }
   };

or

   class A
   {
     A(int aMember)
       : mMember(aMember) { }
   };

or

   class A
   {
     A(int aMember)
       : mMember(aMember) {}
   };

Exactly. If we require braces on their own lines for function bodies everywhere, we wouldn't need to solve this!

Also, I have seen (and written) short one-line method bodies like this:

   class A
   {
     bool IsFlagSet() const
       { return mFlag; }
   };

which I guess should be invalid with brace-on-first-line.  I think I
actually prefer (and don't mind the churn that Ehsan mentions if we
rename things)

   class A
   {
     bool IsFlagSet() const { return mFlag; }
   };

if it's short enough, and if not, then we go to:

   class A
   {
     bool IsFlagSet() const {
       return mFlag;
     }
   };

See my reply to this here. I think when in doubt here, consistency should win. So, yay to brace on its own line for all function bodies.

Cheers,
Ehsan
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to