Rule A7-1-7 (required, implementation, automated)

Each expression statement and identifier declaration shall be placed on a separate line.

Rationale

Declaring an identifier on a separate line makes the identifier declaration easier to find and the source code more readable. Also, combining objects, references and pointers declarations with assignments and function calls on the same line may become confusing.

Exception

It is permitted to declare identifiers in initialization statement of a for loop.

Example

// $Id: A7-1-7.cpp 292454 2017-10-23 13:14:23Z michal.szczepankiewicz $
#include <cstdint>
#include <vector>

typedef std::int32_t* ptr;

// Compliant

typedef std::int32_t *pointer, value; // Non-compliant

void Fn1() noexcept
{
std::int32_t x = 0;
std::int32_t const *p2, z = 1;

// Compliant

std::int32_t y = 7, *p1 = nullptr; // Non-compliant

// Non-compliant

}

void Fn2()
{
std::vector<std::int32_t> v{1, 2, 3, 4, 5};
for (auto iter{v.begin()}, end{v.end()}; iter != end;
++iter) // Compliant by exception
{
// ...
}
}

void Fn3() noexcept
{

std::int32_t x{5};
std::int32_t y{15}; // Non-compliant
x++;
++y; // Non-compliant
for (std::int32_t i{0}; i < 100; ++i)
{
Fn2(); // Compliant
}

}

See also

HIC++ v4.0 [9]: 7.1.1 Declare each identifier on a separate line in a separate declaration. JSF December 2005 [8]: AV Rule 42 Each expression-statement will be on a separate line. JSF December 2005 [8]: AV Rule 152: Multiple variable declarations shall not be allowed on the same line. C++ Core Guidelines [11]: NL.20: Don’t place two statements on the same line.