Rule A8-4-1 (required, implementation, automated)

Functions shall not be defined using the ellipsis notation.

Rationale

Passing arguments via an ellipsis bypasses the type checking performed by the compiler. Additionally, passing an argument with non-POD class type leads to undefined behavior. Variadic templates offer a type-safe alternative for ellipsis notation. If use of a variadic template is not possible, function overloading or function call chaining can be considered.

Example

// $Id: A8-4-1.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $

void Print1(char* format, ...) // Non-compliant - variadic arguments are used

{
// ...

}

template <typename First, typename... Rest>
void Print2(const First& first, const Rest&... args) // Compliant
{
// ...
}

See also

MISRA C++ 2008 [7]: Rule 8-4-1 Functions shall not be defined using the ellipsis notation. HIC++ v4.0 [9]: 14.1.1 Use variadic templates rather than an ellipsis. C++ Core Guidelines [11]: Type.8: Avoid reading from varargs or passing vararg arguments. Prefer variadic template parameters instead. C++ Core Guidelines [11]: F.55: Don’t use va_arg arguments.