| Issue |
71733
|
| Summary |
clang-format enhance SeparateDefinitionBlocks
|
| Labels |
clang-format
|
| Assignees |
|
| Reporter |
FalcoGer
|
I would like an option for the `SeparateDefinitionBlocks` for clang-format to include a setting that does insert empty lines if either definition spans multiple lines, but not if they both fit on the same line.
Example:
Always:
```c++
int f() { return 42; }
int g() { return 43; }
int h()
{
const auto ret = 42;
return ret;
}
int i() { return 44; }
```
Never:
```c++
int f() { return 42; }
int g() { return 43; }
int h()
{
const auto ret = 42;
return ret;
}
int i() { return 44; }
```
SeparateMultiline:
```c++
int f() { return 42; }
int g() { return 43; }
int h()
{
const auto ret = 42;
return ret;
}
int i() { return 44; }
```
This is especially helpful for classes with lots of simple functions that fit in one line.
```c++
template <typename T>
class TypeSafe
{
public:
TypeSafe() : m_value(T()) {}
explicit TypeSafe(const T& value) : m_value(value) {}
explicit TypeSafe(T&& value) : m_value(std::move(value)) {}
TypeSafe(const TypeSafe& other) : m_value(other.m_value) {}
TypeSafe(TypeSafe&& other) noexcept : m_value(std::move(other.m_value)) {}
TypeSafe& operator= (const TypeSafe& other)
{
m_value = other.m_value;
return *this;
}
TypeSafe& operator= (TypeSafe&& other)
{
m_value = std::move(other.m_value);
return *this;
}
operator T () const { return m_value; }
~TypeSafe() = default;
private:
T m_value;
};
```
Would become a lot more compressed and still readable:
```c++
template <typename T>
class TypeSafe
{
public:
TypeSafe() : m_value(T()) {}
explicit TypeSafe(const T& value) : m_value(value) {}
explicit TypeSafe(T&& value) : m_value(std::move(value)) {}
TypeSafe(const TypeSafe& other) : m_value(other.m_value) {}
TypeSafe(TypeSafe&& other) noexcept : m_value(std::move(other.m_value)) {}
TypeSafe& operator= (const TypeSafe& other)
{
m_value = other.m_value;
return *this;
}
TypeSafe& operator= (TypeSafe&& other)
{
m_value = std::move(other.m_value);
return *this;
}
operator T () const { return m_value; }
~TypeSafe() = default;
private:
T m_value;
};
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs