clang 24.0.0git
FormatStyle::ShortFunctionStyle Struct Reference

Different styles for merging short functions containing at most one statement. More...

#include "clang/Format/Format.h"

Public Member Functions

bool operator== (const ShortFunctionStyle &R) const
bool operator!= (const ShortFunctionStyle &R) const
 ShortFunctionStyle ()
 ShortFunctionStyle (bool Empty, bool Inline, bool Other)
bool isAll () const

Static Public Member Functions

static ShortFunctionStyle setEmptyOnly ()
static ShortFunctionStyle setEmptyAndInline ()
static ShortFunctionStyle setInlineOnly ()
static ShortFunctionStyle setAll ()

Public Attributes

bool Empty
 Merge top-level empty functions.
bool Inline
 Merge functions defined inside a class.
bool Other
 Merge all functions fitting on a single line.

Detailed Description

Different styles for merging short functions containing at most one statement.

They can be read as a whole for compatibility. The choices are:

  • None Never merge functions into a single line.
  • InlineOnly Only merge functions defined inside a class. Same as inline, except it does not implies empty: i.e. top level empty functions are not merged either. See Inline of ShortFunctionStyle.
    class Foo {
    void f() { foo(); }
    };
    void f() {
    foo();
    }
    void f() {
    }
  • Empty Only merge empty functions. See Empty of ShortFunctionStyle.
    void f() {}
    void f2() {
    bar2();
    }
  • Inline Only merge functions defined inside a class. Implies empty. See Inline and Empty of ShortFunctionStyle.
    class Foo {
    void f() { foo(); }
    };
    void f() {
    foo();
    }
    void f() {}
  • All Merge all functions fitting on a single line.
    class Foo {
    void f() { foo(); }
    };
    void f() { bar(); }

Also can be specified as a nested configuration flag:

# Example of usage:
AllowShortFunctionsOnASingleLine: InlineOnly
# or more granular control:
AllowShortFunctionsOnASingleLine:
Empty: false
Inline: true
Other: false

Definition at line 898 of file Format.h.

Constructor & Destructor Documentation

◆ ShortFunctionStyle() [1/2]

clang::format::FormatStyle::ShortFunctionStyle::ShortFunctionStyle ( )
inline

Definition at line 935 of file Format.h.

◆ ShortFunctionStyle() [2/2]

clang::format::FormatStyle::ShortFunctionStyle::ShortFunctionStyle ( bool Empty,
bool Inline,
bool Other )
inline

Definition at line 936 of file Format.h.

Member Function Documentation

◆ isAll()

bool clang::format::FormatStyle::ShortFunctionStyle::isAll ( ) const
inline

Definition at line 938 of file Format.h.

◆ operator!=()

bool clang::format::FormatStyle::ShortFunctionStyle::operator!= ( const ShortFunctionStyle & R) const
inline

Definition at line 934 of file Format.h.

◆ operator==()

bool clang::format::FormatStyle::ShortFunctionStyle::operator== ( const ShortFunctionStyle & R) const
inline

Definition at line 931 of file Format.h.

◆ setAll()

ShortFunctionStyle clang::format::FormatStyle::ShortFunctionStyle::setAll ( )
inlinestatic

◆ setEmptyAndInline()

ShortFunctionStyle clang::format::FormatStyle::ShortFunctionStyle::setEmptyAndInline ( )
inlinestatic

◆ setEmptyOnly()

ShortFunctionStyle clang::format::FormatStyle::ShortFunctionStyle::setEmptyOnly ( )
inlinestatic

◆ setInlineOnly()

ShortFunctionStyle clang::format::FormatStyle::ShortFunctionStyle::setInlineOnly ( )
inlinestatic

Member Data Documentation

◆ Empty

bool clang::format::FormatStyle::ShortFunctionStyle::Empty

Merge top-level empty functions.

void f() {}
void f2() {
bar2();
}
void f3() { /* comment */ }

Definition at line 907 of file Format.h.

◆ Inline

bool clang::format::FormatStyle::ShortFunctionStyle::Inline

Merge functions defined inside a class.

class Foo {
void f() { foo(); }
void g() {}
};
void f() {
foo();
}
void f() {
}

Definition at line 920 of file Format.h.

◆ Other

bool clang::format::FormatStyle::ShortFunctionStyle::Other

Merge all functions fitting on a single line.

Please note that this control does not include Empty

class Foo {
void f() { foo(); }
};
void f() { bar(); }

Definition at line 929 of file Format.h.


The documentation for this struct was generated from the following file: