Skip to main content

C++ Coding Violations

Cyclopt analyzes your C++ code to identify coding and security violations. Each check below lists its Rule ID, a description, guidance on what to do, a default severity, and its scope.

tip

Every check has a Rule ID (shown in code font). Use it to silence an individual finding directly in your source with a cyclopt-ignore comment, or to exclude it project-wide in the configuration file.

Scope tells you how a rule is evaluated:

  • File: the check runs on each file on its own.
  • Solution-wide: the check needs the whole codebase (for example, to decide a member is never used anywhere).

File-level checks

Clang Static Analyzer Finding

Rule ID: clang-analyzer-*

Description: Issue detected by the Clang Static Analyzer, indicating a potential bug or security vulnerability.

Issue detected by the Clang Static Analyzer, indicating a potential bug or security vulnerability.

Severity Scope

Bugprone Code Pattern

Rule ID: bugprone-*

Description: Code pattern that is likely to result in a bug or undefined behavior.

Code pattern that is likely to result in a bug or undefined behavior.

Severity Scope

Assert Statement Has Side Effects

Rule ID: bugprone-assert-side-effect

Description: Assert statement contains an expression with side effects that may be removed in release builds.

Assert statement contains an expression with side effects that may be removed in release builds.

Severity Scope

Bad Example
assert(x++ > 0);
Good Example
assert(x > 0);
x++;

Potentially Infinite Loop

Rule ID: bugprone-infinite-loop

Description: Loop condition does not progress toward termination.

Loop condition does not progress toward termination.

Severity Scope

Bad Example
int i = 0;
while (i < 10)
Process();
Good Example
int i = 0;
while (i < 10)
Process(i++);

Forwarding Reference Moved Instead of Forwarded

Rule ID: bugprone-move-forwarding-reference

Description: Forwarding reference should use std::forward instead of std::move.

Forwarding reference should use std::forward instead of std::move.

Severity Scope

Bad Example
template <typename T>
void Forward(T&& value) {
auto copy = std::move(value);
}
Good Example
template <typename T>
void Forward(T&& value) {
auto copy = std::forward<T>(value);
}

Signed Char Misuse

Rule ID: bugprone-signed-char-misuse

Description: Signed char used in a context that expects unsigned or a different type.

Signed char used in a context that expects unsigned or a different type.

Severity Scope

Bad Example
char c = input[0];
bool valid = isalpha(c);
Good Example
unsigned char c = input[0];
bool valid = isalpha(c);

Suspicious sizeof Expression

Rule ID: bugprone-sizeof-expression

Description: sizeof expression that is likely a mistake, such as sizeof on a pointer instead of the pointed-to type.

sizeof expression that is likely a mistake, such as sizeof on a pointer instead of the pointed-to type.

Severity Scope

Bad Example
int values[100];
int* ptr = values;
size_t n = sizeof(ptr) / sizeof(int);
Good Example
int values[100];
size_t n = sizeof(values) / sizeof(values[0]);

Spurious Wake-Up Functions

Rule ID: bugprone-spuriously-wake-up-functions

Description: Use of condition variable wait without a predicate lambda, which is susceptible to spurious wake-ups.

Use of condition variable wait without a predicate lambda, which is susceptible to spurious wake-ups.

Severity Scope

Bad Example
std::unique_lock<std::mutex> lock(mutex);
cv.wait(lock);
Good Example
std::unique_lock<std::mutex> lock(mutex);
cv.wait(lock, [] { return ready; });

Undefined Memory Manipulation

Rule ID: bugprone-undefined-memory-manipulation

Description: Use of memory manipulation functions on non-trivially-copyable types causes undefined behavior.

Use of memory manipulation functions on non-trivially-copyable types causes undefined behavior.

Severity Scope

Bad Example
std::string name = "abc";
std::memcpy(&other, &name, sizeof(name));
Good Example
std::string name = "abc";
other = name;

Unused RAII Object

Rule ID: bugprone-unused-raii

Description: RAII object created but not used; the object is destroyed immediately, likely missing a variable name.

RAII object created but not used; the object is destroyed immediately, likely missing a variable name.

Severity Scope

Bad Example
std::scoped_lock<std::mutex>;
Good Example
std::scoped_lock<std::mutex> lock(mutex);

Use After Move

Rule ID: bugprone-use-after-move

Description: Object used after being moved from, which leaves it in an unspecified state.

Object used after being moved from, which leaves it in an unspecified state.

Severity Scope

Bad Example
std::string source = "hello";
auto moved = std::move(source);
Use(source);
Good Example
std::string source = "hello";
auto moved = std::move(source);
Use(moved);

C++ Core Guideline Violation

Rule ID: cppcoreguidelines-*

Description: Code pattern that violates the C++ Core Guidelines.

Code pattern that violates the C++ Core Guidelines.

Severity Scope

Avoid goto Statement

Rule ID: cppcoreguidelines-avoid-goto

Description: Use of goto statement violates C++ Core Guidelines. Prefer structured control flow.

Use of goto statement violates C++ Core Guidelines. Prefer structured control flow.

Severity Scope

Bad Example
for (int i = 0; i < 10; i++) {
if (bad)
goto exit;
Process(i);
}
exit:
return;
Good Example
for (int i = 0; i < 10; i++) {
if (bad)
break;
Process(i);
}
return;

Avoid Magic Numbers

Rule ID: cppcoreguidelines-avoid-magic-numbers

Description: Named constants should be used instead of literal magic numbers.

Named constants should be used instead of literal magic numbers.

Severity Scope

Bad Example
double total = price * 0.08;
Good Example
constexpr double TAX_RATE = 0.08;
double total = price * TAX_RATE;

Always Initialize Variables

Rule ID: cppcoreguidelines-init-variables

Description: Variables should be initialized at the point of declaration to avoid undefined behavior.

Variables should be initialized at the point of declaration to avoid undefined behavior.

Severity Scope

Bad Example
int count;
std::cin >> count;
Good Example
int count = 0;
std::cin >> count;

Avoid Global Object Initialization Order

Rule ID: cppcoreguidelines-interfaces-global-init

Description: Initialization order of non-local static objects across translation units is undefined.

Initialization order of non-local static objects across translation units is undefined.

Severity Scope

Bad Example
// a.cpp
int value = ReadConfig();
Good Example
// a.cpp
int value = 0;
void Init() { value = ReadConfig(); }

Avoid Narrowing Conversions

Rule ID: cppcoreguidelines-narrowing-conversions

Description: Narrowing conversions may lose data. Use explicit casts or wider types.

Narrowing conversions may lose data. Use explicit casts or wider types.

Severity Scope

Bad Example
int count = 3.14;
Good Example
int count = static_cast<int>(3.14);

Prefer RAII Over malloc/free

Rule ID: cppcoreguidelines-no-malloc

Description: C-style memory management should be replaced with RAII (smart pointers, containers).

C-style memory management should be replaced with RAII (smart pointers, containers).

Severity Scope

Bad Example
int* values = static_cast<int*>(std::malloc(n * sizeof(int)));
Good Example
auto values = std::make_unique<int[]>(n);

Owning Memory Management Issue

Rule ID: cppcoreguidelines-owning-memory

Description: Raw pointer used as an owner; prefer smart pointers or containers.

Raw pointer used as an owner; prefer smart pointers or containers.

Severity Scope

Bad Example
int* CreateArray(std::size_t n) {
return new int[n];
}
Good Example
std::unique_ptr<int[]> CreateArray(std::size_t n) {
return std::make_unique<int[]>(n);
}

Avoid C-Style Casts

Rule ID: cppcoreguidelines-pro-type-cstyle-cast

Description: C-style casts are dangerous and hard to find in code. Use C++ casts (static_cast, dynamic_cast, const_cast, reinterpret_cast).

C-style casts are dangerous and hard to find in code. Use C++ casts (static_cast, dynamic_cast, const_cast, reinterpret_cast).

Severity Scope

Bad Example
double result = (double)value / count;
Good Example
double result = static_cast<double>(value) / count;

Member Initialization Missing

Rule ID: cppcoreguidelines-pro-type-member-init

Description: Constructor should initialize all class members to avoid undefined behavior.

Constructor should initialize all class members to avoid undefined behavior.

Severity Scope

Bad Example
class Account {
int balance;
public:
Account() {}
};
Good Example
class Account {
int balance = 0;
public:
Account() {}
};

Avoid reinterpret_cast

Rule ID: cppcoreguidelines-pro-type-reinterpret-cast

Description: reinterpret_cast is type-unsafe and should be avoided where possible.

reinterpret_cast is type-unsafe and should be avoided where possible.

Severity Scope

Bad Example
int* address = reinterpret_cast<int*>(raw);
Good Example
auto* address = static_cast<int*>(raw);

Unsafe Union Access

Rule ID: cppcoreguidelines-pro-type-union-access

Description: Accessing a union member that is not the active one is undefined behavior.

Accessing a union member that is not the active one is undefined behavior.

Severity Scope

Bad Example
union Value {
int i;
float f;
};
Value v;
v.f = 1.5f;
Use(v.i);
Good Example
std::variant<int, float> v;
v = 1.5f;
Use(std::get<float>(v));

Object Slicing

Rule ID: cppcoreguidelines-slicing

Description: Slicing occurs when a derived class object is assigned to a base class object by value.

Slicing occurs when a derived class object is assigned to a base class object by value.

Severity Scope

Bad Example
Base base = derived;
Good Example
const Base& base = derived;

Rule of Five Violation

Rule ID: cppcoreguidelines-special-member-functions

Description: Class with user-defined destructor, copy, or move operations should define all five special member functions.

Class with user-defined destructor, copy, or move operations should define all five special member functions.

Severity Scope

Bad Example
class Buffer {
public:
~Buffer();
Buffer(const Buffer&);
Buffer& operator=(const Buffer&);
};
Good Example
class Buffer {
public:
~Buffer();
Buffer(const Buffer&);
Buffer& operator=(const Buffer&);
Buffer(Buffer&&) noexcept;
Buffer& operator=(Buffer&&) noexcept;
};

Performance Issue

Rule ID: performance-*

Description: Code pattern that may cause unnecessary performance overhead.

Code pattern that may cause unnecessary performance overhead.

Severity Scope

Inefficient For-Range Copy

Rule ID: performance-for-range-copy

Description: For-range loop copies elements unnecessarily; use const reference instead.

For-range loop copies elements unnecessarily; use const reference instead.

Severity Scope

Bad Example
for (auto item : items)
Process(item);
Good Example
for (const auto& item : items)
Process(item);

Implicit Conversion in Loop

Rule ID: performance-implicit-conversion-in-loop

Description: Implicit type conversion in a loop causes repeated conversions, impacting performance.

Implicit type conversion in a loop causes repeated conversions, impacting performance.

Severity Scope

Bad Example
for (int i = 0; i < items.size(); i++)
Process(items[i]);
Good Example
for (std::size_t i = 0; i < items.size(); i++)
Process(items[i]);

Inefficient String Concatenation

Rule ID: performance-inefficient-string-concatenation

Description: Repeated string concatenation creates temporary objects. Use += or std::ostringstream.

Repeated string concatenation creates temporary objects. Use += or std::ostringstream.

Severity Scope

Bad Example
std::string message = "User: ";
message = message + name + ", id=" + id;
Good Example
std::ostringstream out;
out << "User: " << name << ", id=" << id;
std::string message = out.str();

Inefficient Vector Operation

Rule ID: performance-inefficient-vector-operation

Description: Vector operation that may cause repeated reallocations; consider reserve() first.

Vector operation that may cause repeated reallocations; consider reserve() first.

Severity Scope

Bad Example
std::vector<int> values;
for (int i = 0; i < 1000; i++)
values.push_back(i);
Good Example
std::vector<int> values;
values.reserve(1000);
for (int i = 0; i < 1000; i++)
values.push_back(i);

Moving a Const Argument

Rule ID: performance-move-const-arg

Description: std::move on a const object has no effect since const prevents moving.

std::move on a const object has no effect since const prevents moving.

Severity Scope

Bad Example
const std::string name = "abc";
auto copy = std::move(name);
Good Example
std::string name = "abc";
auto copy = std::move(name);

Move Constructor Should Be noexcept

Rule ID: performance-noexcept-move-constructor

Description: Move constructors should be marked noexcept for optimal standard library performance.

Move constructors should be marked noexcept for optimal standard library performance.

Severity Scope

Bad Example
class Buffer {
public:
Buffer(Buffer&& other) {}
};
Good Example
class Buffer {
public:
Buffer(Buffer&& other) noexcept {}
};

Trivially Destructible Type

Rule ID: performance-trivially-destructible

Description: Destructor defined but type is trivially destructible; remove empty destructor.

Destructor defined but type is trivially destructible; remove empty destructor.

Severity Scope

Bad Example
class Config {
public:
~Config() {}
};
Good Example
class Config {
public:
};

Unnecessary Copy Initialization

Rule ID: performance-unnecessary-copy-initialization

Description: Local variable is copy-initialized but can be bound to a reference or moved.

Local variable is copy-initialized but can be bound to a reference or moved.

Severity Scope

Bad Example
Widget widget = CreateWidget();
Good Example
auto&& widget = CreateWidget();

Unnecessary Value Parameter

Rule ID: performance-unnecessary-value-param

Description: Parameter is copied unnecessarily; use const reference instead.

Parameter is copied unnecessarily; use const reference instead.

Severity Scope

Bad Example
void SetName(std::string name);
Good Example
void SetName(const std::string& name);

Readability Issue

Rule ID: readability-*

Description: Code pattern that reduces readability and maintainability.

Code pattern that reduces readability and maintainability.

Severity Scope

Missing Braces Around Statement

Rule ID: readability-braces-around-statements

Description: Multi-line control statement without braces can lead to confusing logic and bugs.

Multi-line control statement without braces can lead to confusing logic and bugs.

Severity Scope

Bad Example
if (ready)
Process();
Finalize();
Good Example
if (ready) {
Process();
}
Finalize();

Redundant const Return Type

Rule ID: readability-const-return-type

Description: Return type const qualifier on a non-pointer/primitve type is meaningless.

Return type const qualifier on a non-pointer/primitve type is meaningless.

Severity Scope

Bad Example
const int GetValue();
Good Example
int GetValue();

Check Container Empty With empty()

Rule ID: readability-container-size-empty

Description: Use .empty() instead of .size() == 0 for clarity and potentially better performance.

Use .empty() instead of .size() == 0 for clarity and potentially better performance.

Severity Scope

Bad Example
if (items.size() == 0)
return;
Good Example
if (items.empty())
return;

Member Function Could Be Static

Rule ID: readability-convert-member-functions-to-static

Description: Member function does not access any non-static members and could be made static.

Member function does not access any non-static members and could be made static.

Severity Scope

Bad Example
class Utility {
public:
int Square(int n) { return n * n; }
};
Good Example
class Utility {
public:
static int Square(int n) { return n * n; }
};

Redundant Null Check Before delete

Rule ID: readability-delete-null-pointer

Description: delete on a null pointer is safe, so the null check is redundant.

delete on a null pointer is safe, so the null check is redundant.

Severity Scope

Bad Example
if (ptr != nullptr)
delete ptr;
Good Example
delete ptr;

Unnecessary else After return

Rule ID: readability-else-after-return

Description: else is unnecessary after a return statement; remove it to reduce nesting.

else is unnecessary after a return statement; remove it to reduce nesting.

Severity Scope

Bad Example
if (valid) {
return value;
} else {
return 0;
}
Good Example
if (valid) {
return value;
}
return 0;

Function Cognitive Complexity Too High

Rule ID: readability-function-cognitive-complexity

Description: Function has high cognitive complexity, making it hard to understand and maintain.

Function has high cognitive complexity, making it hard to understand and maintain.

Severity Scope

Bad Example
void Validate(const Request& r) {
if (r.A) {
if (r.B) {
if (r.C) {
Process(r);
}
}
}
}
Good Example
void Validate(const Request& r) {
if (!r.A || !r.B || !r.C) {
return;
}
Process(r);
}

Identifier Length Issue

Rule ID: readability-identifier-length

Description: Identifier name is too short or too long, reducing code readability.

Identifier name is too short or too long, reducing code readability.

Severity Scope

Bad Example
for (int i = 0; i < size; i++)
Process(i);
Good Example
for (int index = 0; index < size; index++)
Process(index);

Implicit Bool Conversion

Rule ID: readability-implicit-bool-conversion

Description: Implicit conversion to bool may hide bugs; use explicit comparison.

Implicit conversion to bool may hide bugs; use explicit comparison.

Severity Scope

Bad Example
if (count)
Process();
Good Example
if (count != 0)
Process();

Isolate Declarations

Rule ID: readability-isolate-declaration

Description: Each variable should be declared on its own line for readability.

Each variable should be declared on its own line for readability.

Severity Scope

Bad Example
int width = 10, height = 20;
Good Example
int width = 10;
int height = 20;

Member Function Could Be const

Rule ID: readability-make-member-function-const

Description: Member function does not modify the object and should be marked const.

Member function does not modify the object and should be marked const.

Severity Scope

Bad Example
class Account {
int balance = 0;
public:
int GetBalance() { return balance; }
};
Good Example
class Account {
int balance = 0;
public:
int GetBalance() const { return balance; }
};

Misleading Indentation

Rule ID: readability-misleading-indentation

Description: Indentation does not match the actual control flow, which is misleading and error-prone.

Indentation does not match the actual control flow, which is misleading and error-prone.

Severity Scope

Bad Example
if (ready)
Process();
Finalize();
Good Example
if (ready) {
Process();
Finalize();
}

Named Parameter Missing

Rule ID: readability-named-parameter

Description: Parameter in function declaration is unnamed; use a descriptive name.

Parameter in function declaration is unnamed; use a descriptive name.

Severity Scope

Bad Example
void SetTimeout(int);
Good Example
void SetTimeout(int seconds);

Parameter Should Be const

Rule ID: readability-non-const-parameter

Description: Function parameter is not modified and should be const.

Function parameter is not modified and should be const.

Severity Scope

Bad Example
void Print(const std::string& s, std::size_t* size);
Good Example
void Print(const std::string& s, const std::size_t* size);

Redundant Access Specifier

Rule ID: readability-redundant-access-specifiers

Description: Access specifier is redundant because it repeats the current default access level.

Access specifier is redundant because it repeats the current default access level.

Severity Scope

Bad Example
class Config {
public:
int retries;
public:
int timeout;
};
Good Example
class Config {
public:
int retries;
int timeout;
};

Redundant Control Flow

Rule ID: readability-redundant-control-flow

Description: Unnecessary return, continue, or break statement at the end of a block.

Unnecessary return, continue, or break statement at the end of a block.

Severity Scope

Bad Example
void Process(bool done) {
if (done) {
Finalize();
}
return;
}
Good Example
void Process(bool done) {
if (done) {
Finalize();
}
}

Redundant Declaration

Rule ID: readability-redundant-declaration

Description: Variable declaration is redundant because the variable is immediately reassigned.

Variable declaration is redundant because the variable is immediately reassigned.

Severity Scope

Bad Example
int count;
count = ComputeCount();
Good Example
int count = ComputeCount();

Redundant Function Pointer Dereference

Rule ID: readability-redundant-function-ptr-dereference

Description: Calling a function pointer does not require explicit dereference.

Calling a function pointer does not require explicit dereference.

Severity Scope

Bad Example
int result = (*callback)(value);
Good Example
int result = callback(value);

Redundant smartptr::get() Call

Rule ID: readability-redundant-smartptr-get

Description: Call to .get() is unnecessary since the smart pointer supports the same interface.

Call to .get() is unnecessary since the smart pointer supports the same interface.

Severity Scope

Bad Example
std::unique_ptr<Widget> widget;
widget.get()->Render();
Good Example
std::unique_ptr<Widget> widget;
widget->Render();

Redundant string::c_str() Call

Rule ID: readability-redundant-string-cstr

Description: Call to .c_str() is unnecessary since C++ strings can be used directly.

Call to .c_str() is unnecessary since C++ strings can be used directly.

Severity Scope

Bad Example
std::string text = "hello";
Accept(text.c_str());
Good Example
std::string text = "hello";
Accept(text);

Redundant String Initialization

Rule ID: readability-redundant-string-init

Description: Default-initialized std::string is already empty; = "" is redundant.

Default-initialized std::string is already empty; = "" is redundant.

Severity Scope

Bad Example
std::string name = "";
Good Example
std::string name;

Simplify Boolean Expression

Rule ID: readability-simplify-boolean-expr

Description: Boolean expression can be simplified for clarity (e.g. return x instead of x ? true : false).

Boolean expression can be simplified for clarity (e.g. return x instead of x ? true : false).

Severity Scope

Bad Example
return value > 0 ? true : false;
Good Example
return value > 0;

Simplify Subscript Expression

Rule ID: readability-simplify-subscript-expr

Description: Subscript expression on a pointer can be simplified to a dereference.

Subscript expression on a pointer can be simplified to a dereference.

Severity Scope

Bad Example
int value = ptr[0];
Good Example
int value = *ptr;

Static Member Accessed Through Instance

Rule ID: readability-static-accessed-through-instance

Description: Static member accessed through an instance rather than the class name.

Static member accessed through an instance rather than the class name.

Severity Scope

Bad Example
Logger logger;
logger.Log("message");
Good Example
Logger::Log("message");

String Comparison Using compare()

Rule ID: readability-string-compare

Description: Use == or != instead of string::compare() for equality checks.

Use == or != instead of string::compare() for equality checks.

Severity Scope

Bad Example
if (text.compare("done") == 0)
Finalize();
Good Example
if (text == "done")
Finalize();

Incorrect unique_ptr Release Pattern

Rule ID: readability-uniqueptr-delete-release

Description: Calling delete on the result of unique_ptr::release() defeats the purpose of the smart pointer.

Calling delete on the result of unique_ptr::release() defeats the purpose of the smart pointer.

Severity Scope

Bad Example
std::unique_ptr<Widget> widget = Create();
delete widget.release();
Good Example
std::unique_ptr<Widget> widget = Create();
// let the smart pointer destroy the object

Modernization Opportunity

Rule ID: modernize-*

Description: Code pattern that can be modernized using C++11/14/17/20 features.

Code pattern that can be modernized using C++11/14/17/20 features.

Severity Scope

Avoid std::bind

Rule ID: modernize-avoid-bind

Description: Prefer lambdas over std::bind for better readability and performance.

Prefer lambdas over std::bind for better readability and performance.

Severity Scope

Bad Example
auto handler = std::bind(&App::OnClick, this, std::placeholders::_1);
Good Example
auto handler = [this](int id) { OnClick(id); };

Deprecated C Headers

Rule ID: modernize-deprecated-headers

Description: Use C++ versions of C standard library headers (<cstdlib> instead of <stdlib.h>).

Use C++ versions of C standard library headers (<cstdlib> instead of <stdlib.h>).

Severity Scope

Bad Example
#include <stdlib.h>
Good Example
#include <cstdlib>

Use Range-Based For Loop

Rule ID: modernize-loop-convert

Description: Loop can be converted to a range-based for loop for simplicity.

Loop can be converted to a range-based for loop for simplicity.

Severity Scope

Bad Example
for (std::size_t i = 0; i < items.size(); i++)
Process(items[i]);
Good Example
for (const auto& item : items)
Process(item);

Use std::make_shared

Rule ID: modernize-make-shared

Description: Use std::make_shared instead of explicit new and shared_ptr constructor for exception safety.

Use std::make_shared instead of explicit new and shared_ptr constructor for exception safety.

Severity Scope

Bad Example
std::shared_ptr<Widget> widget(new Widget());
Good Example
auto widget = std::make_shared<Widget>();

Use std::make_unique

Rule ID: modernize-make-unique

Description: Use std::make_unique instead of explicit new and unique_ptr constructor for exception safety.

Use std::make_unique instead of explicit new and unique_ptr constructor for exception safety.

Severity Scope

Bad Example
std::unique_ptr<Widget> widget(new Widget());
Good Example
auto widget = std::make_unique<Widget>();

Pass by Value Then Move

Rule ID: modernize-pass-by-value

Description: Pass by value and move for sink parameters instead of const reference + copy.

Pass by value and move for sink parameters instead of const reference + copy.

Severity Scope

Bad Example
void SetName(const std::string& name) {
this->name = name;
}
Good Example
void SetName(std::string name) {
this->name = std::move(name);
}

Use Raw String Literal

Rule ID: modernize-raw-string-literal

Description: String with many escaped characters can be made more readable with a raw string literal.

String with many escaped characters can be made more readable with a raw string literal.

Severity Scope

Bad Example
std::string pattern = "a\\d+\\s*b";
Good Example
std::string pattern = R"(ad+s*b)";

Redundant Void Argument

Rule ID: modernize-redundant-void-arg

Description: Redundant void argument in function declaration; just use empty parentheses.

Redundant void argument in function declaration; just use empty parentheses.

Severity Scope

Bad Example
int GetValue(void);
Good Example
int GetValue();

Use Braced Init List For Return

Rule ID: modernize-return-braced-init-list

Description: Return braced initializer list instead of creating a named temporary.

Return braced initializer list instead of creating a named temporary.

Severity Scope

Bad Example
std::pair<int, int> GetBounds() {
return std::pair<int, int>(0, 100);
}
Good Example
std::pair<int, int> GetBounds() {
return {0, 100};
}

Use shrink_to_fit

Rule ID: modernize-shrink-to-fit

Description: Clear then swap idiom can be replaced with shrink_to_fit() in C++17.

Clear then swap idiom can be replaced with shrink_to_fit() in C++17.

Severity Scope

Bad Example
std::vector<int> values;
std::vector<int>(values).swap(values);
Good Example
std::vector<int> values;
values.shrink_to_fit();

Use Unary static_assert

Rule ID: modernize-unary-static-assert

Description: Use the unary form of static_assert (without a message string) in C++17.

Use the unary form of static_assert (without a message string) in C++17.

Severity Scope

Bad Example
static_assert(sizeof(int) == 4, "int must be 4 bytes");
Good Example
static_assert(sizeof(int) == 4);

Use auto

Rule ID: modernize-use-auto

Description: Type is already specified in the initializer; use auto to avoid redundancy.

Type is already specified in the initializer; use auto to avoid redundancy.

Severity Scope

Bad Example
std::vector<int> values;
std::vector<int>::iterator it = values.begin();
Good Example
std::vector<int> values;
auto it = values.begin();

Use Boolean Literals

Rule ID: modernize-use-bool-literals

Description: Use true/false instead of integer literals 1/0 for boolean returns.

Use true/false instead of integer literals 1/0 for boolean returns.

Severity Scope

Bad Example
bool valid = 1;
Good Example
bool valid = true;

Use Default Member Initializers

Rule ID: modernize-use-default-member-init

Description: Use default member initializers instead of constructor initializer lists for simple defaults.

Use default member initializers instead of constructor initializer lists for simple defaults.

Severity Scope

Bad Example
class Config {
int retries;
public:
Config() : retries(3) {}
};
Good Example
class Config {
int retries = 3;
public:
Config() {}
};

Use = default

Rule ID: modernize-use-equals-default

Description: Use = default for compiler-provided special member functions instead of empty implementations.

Use = default for compiler-provided special member functions instead of empty implementations.

Severity Scope

Bad Example
class Buffer {
public:
~Buffer() {}
};
Good Example
class Buffer {
public:
~Buffer() = default;
};

Use = delete

Rule ID: modernize-use-equals-delete

Description: Use = delete for deleted member functions instead of private declarations.

Use = delete for deleted member functions instead of private declarations.

Severity Scope

Bad Example
class NonCopyable {
private:
NonCopyable(const NonCopyable&);
};
Good Example
class NonCopyable {
public:
NonCopyable(const NonCopyable&) = delete;
};

Use [[nodiscard]]

Rule ID: modernize-use-nodiscard

Description: Function returning a value that should not be ignored should be marked [[nodiscard]].

Function returning a value that should not be ignored should be marked [[nodiscard]].

Severity Scope

Bad Example
int GetCount();
Good Example
[[nodiscard]] int GetCount();

Use noexcept

Rule ID: modernize-use-noexcept

Description: Functions that do not throw exceptions should be marked noexcept.

Functions that do not throw exceptions should be marked noexcept.

Severity Scope

Bad Example
int GetSize() { return size; }
Good Example
int GetSize() noexcept { return size; }

Use nullptr Instead of NULL

Rule ID: modernize-use-nullptr

Description: Use nullptr instead of NULL or 0 for pointer values.

Use nullptr instead of NULL or 0 for pointer values.

Severity Scope

Bad Example
int* ptr = NULL;
Good Example
int* ptr = nullptr;

Use override Specifier

Rule ID: modernize-use-override

Description: Overriding virtual functions should be marked with the override specifier.

Overriding virtual functions should be marked with the override specifier.

Severity Scope

Bad Example
class Derived : public Base {
public:
void Draw();
};
Good Example
class Derived : public Base {
public:
void Draw() override;
};

Use Transparent Functors

Rule ID: modernize-use-transparent-functors

Description: Use transparent functors (std::less<>) instead of non-transparent ones to avoid type conversions.

Use transparent functors (std::less<>) instead of non-transparent ones to avoid type conversions.

Severity Scope

Bad Example
std::map<std::string, int, std::less<std::string>> lookup;
Good Example
std::map<std::string, int, std::less<>> lookup;

Use std::uncaught_exceptions

Rule ID: modernize-use-uncaught-exceptions

Description: Use std::uncaught_exceptions (C++17) instead of the deprecated std::uncaught_exception.

Use std::uncaught_exceptions (C++17) instead of the deprecated std::uncaught_exception.

Severity Scope

Bad Example
bool hasActive = std::uncaught_exception();
Good Example
bool hasActive = std::uncaught_exceptions() > 0;

Use using Instead of typedef

Rule ID: modernize-use-using

Description: Use using declarations instead of C-style typedef for better readability.

Use using declarations instead of C-style typedef for better readability.

Severity Scope

Bad Example
typedef unsigned int uint;
Good Example
using uint = unsigned int;

Security Concern

Rule ID: security-*

Description: Code pattern that may introduce a security vulnerability.

Code pattern that may introduce a security vulnerability.

Severity Scope

Miscellaneous Issue

Rule ID: misc-*

Description: Code pattern that may indicate a problem.

Code pattern that may indicate a problem.

Severity Scope

Const Correctness Issue

Rule ID: misc-const-correctness

Description: Variable could be declared const to improve safety and readability.

Variable could be declared const to improve safety and readability.

Severity Scope

Bad Example
int value = 42;
int& ref = value;
Use(ref);
Good Example
int value = 42;
const int& ref = value;
Use(ref);

Definitions in Header File

Rule ID: misc-definitions-in-headers

Description: Function or variable definition in a header file may cause ODR violations.

Function or variable definition in a header file may cause ODR violations.

Severity Scope

Bad Example
// helper.h
int Square(int n) { return n * n; }
Good Example
// helper.h
inline int Square(int n) { return n * n; }

Misplaced Const Qualifier

Rule ID: misc-misplaced-const

Description: Const qualifier in a type is placed in a misleading position.

Const qualifier in a type is placed in a misleading position.

Severity Scope

Bad Example
int const* ptr;
Good Example
const int* ptr;

Recursion Detected

Rule ID: misc-no-recursion

Description: Recursive function call detected; consider iterative alternative or ensure bounded depth.

Recursive function call detected; consider iterative alternative or ensure bounded depth.

Severity Scope

Bad Example
int Factorial(int n) {
return n * Factorial(n - 1);
}
Good Example
int Factorial(int n) {
int result = 1;
for (int i = 2; i <= n; i++)
result *= i;
return result;
}

Non-Private Member Variables in Class

Rule ID: misc-non-private-member-variables-in-classes

Description: Class has non-private member variables; prefer private members with accessors.

Class has non-private member variables; prefer private members with accessors.

Severity Scope

Bad Example
class Account {
public:
int balance;
};
Good Example
class Account {
private:
int balance;
public:
int GetBalance() const { return balance; }
};

Redundant Expression

Rule ID: misc-redundant-expression

Description: Expression is redundant (e.g., comparing a value against itself).

Expression is redundant (e.g., comparing a value against itself).

Severity Scope

Bad Example
if (ready && ready)
Process();
Good Example
if (ready)
Process();

Use static_assert

Rule ID: misc-static-assert

Description: Use static_assert instead of assert for compile-time checks.

Use static_assert instead of assert for compile-time checks.

Severity Scope

Bad Example
assert(sizeof(int) == 4);
Good Example
static_assert(sizeof(int) == 4, "int must be 4 bytes");

Throw By Value, Catch By Reference

Rule ID: misc-throw-by-value-catch-by-reference

Description: Exceptions should be thrown by value and caught by const reference.

Exceptions should be thrown by value and caught by const reference.

Severity Scope

Bad Example
try {
throw std::runtime_error("failed");
} catch (std::runtime_error error) {
Handle(error);
}
Good Example
try {
throw std::runtime_error("failed");
} catch (const std::runtime_error& error) {
Handle(error);
}

Unconventional Assignment Operator

Rule ID: misc-unconventional-assign-operator

Description: Copy assignment operator does not follow the conventional pattern (return *this).

Copy assignment operator does not follow the conventional pattern (return *this).

Severity Scope

Bad Example
class Widget {
public:
void operator=(const Widget& other) { /* ... */ }
};
Good Example
class Widget {
public:
Widget& operator=(const Widget& other) { /* ... */ return *this; }
};

Incorrect unique_ptr Reset/Release Pattern

Rule ID: misc-uniqueptr-reset-release

Description: Use std::unique_ptr::reset() instead of release() followed by reset() to avoid leaks.

Use std::unique_ptr::reset() instead of release() followed by reset() to avoid leaks.

Severity Scope

Bad Example
std::unique_ptr<Widget> widget;
widget.reset(widget.release());
Good Example
std::unique_ptr<Widget> widget;
// assignment or reset with a new pointer

Unused Alias Declaration

Rule ID: misc-unused-alias-decls

Description: Namespace alias or type alias declared but never used.

Namespace alias or type alias declared but never used.

Severity Scope

Bad Example
using StringList = std::vector<std::string>;
Good Example
using StringList = std::vector<std::string>;
StringList names = LoadNames();

Unused Parameter

Rule ID: misc-unused-parameters

Description: Function parameter is declared but never used.

Function parameter is declared but never used.

Severity Scope

Bad Example
void Handle(int eventId, int unusedCode);
Good Example
void Handle(int eventId);

Unused Using Declaration

Rule ID: misc-unused-using-decls

Description: Using declaration is unused and can be removed.

Using declaration is unused and can be removed.

Severity Scope

Bad Example
using std::string;
Good Example
using std::string;
string name = LoadName();

Security

Cyclopt scans your C++ code for security vulnerabilities, injection, insecure configuration, weak cryptography, data exposure, and more. Each finding below lists its Rule ID, what it detects and how to fix it, a severity, and the relevant CWE/OWASP classification.

note

Security findings are mapped to industry classifications (CWE and OWASP).


Correctness C String Equality

Rule ID: correctness-c-string-equality

Description: Using == on char* performs pointer comparison, not string comparison. Use strcmp() or std::string::operator== instead.

CWE: CWE-697

Severity Category

Correctness Double Goto

Rule ID: correctness-double-goto

Description: The second goto statement will always be executed regardless of the condition because it is not part of the if block. Add braces {} to make the intent clear and correct.

Severity Category

Correctness Incorrect Use Ato Fn

Rule ID: correctness-incorrect-use-ato-fn

Description: Avoid the ato*() family of functions. Their use can lead to undefined behavior on input overflow and lack error handling. Prefer the strto*() family of functions (strtol(), strtoll(), strtoul(), etc.) or C++ facilities like std::from_chars.

CWE: CWE-190, CWE-20

Severity Category

Correctness Incorrect Use Sscanf Fn

Rule ID: correctness-incorrect-use-sscanf-fn

Description: Avoid sscanf() for number conversions. Its use can lead to undefined behavior on overflow, slow processing, and lack of error handling. Prefer the strto*() family of functions or C++ facilities like std::from_chars.

CWE: CWE-190

Severity Category

Double Free

Rule ID: double-free

Description: Variable '$VAR' was freed twice. This can lead to undefined behavior.

CWE: CWE-415 · OWASP: A01:2017, A03:2021, A05:2025

Severity Category

Function Use After Free

Rule ID: function-use-after-free

Description: Variable '$VAR' was passed to a function after being freed. This can lead to undefined behavior.

CWE: CWE-416

Severity Category

Info Leak On Non Formatted String

Rule ID: info-leak-on-non-formatted-string

Description: Use %s, %d, %c... to format your variables, otherwise this could leak information.

CWE: CWE-532 · OWASP: A09:2021, A09:2025

Severity Category

Insecure Use Gets Fn

Rule ID: insecure-use-gets-fn

Description: Avoid 'gets()'. This function does not consider buffer boundaries and can lead to buffer overflows. Use 'fgets()' or 'gets_s()' instead.

CWE: CWE-676

Severity Category

Insecure Use Memset

Rule ID: insecure-use-memset

Description: When handling sensitive information in a buffer, it's important to ensure that the data is securely erased before the buffer is deleted or reused. While memset() is commonly used for this purpose, it can leave sensitive information behind due to compiler optimizations or other factors. To avoid this potential vulnerability, it's recommended to use the memset_s() function instead. memset_s() is a standardized function that securely overwrites the memory with a specified value, making it more difficult for an attacker to recover any sensitive data that was stored in the buffer. By using memset_s() instead of memset(), you can help to ensure that your application is more secure and less vulnerable to exploits that rely on residual data in memory.

CWE: CWE-14 · OWASP: A04:2021, A06:2025

Severity Category

Insecure Use Printf Fn

Rule ID: insecure-use-printf-fn

Description: Avoid using user-controlled format strings passed into 'sprintf', 'printf' and 'vsprintf'. These functions put you at risk of buffer overflow vulnerabilities through the use of format string exploits. Instead, use 'snprintf' and 'vsnprintf'.

CWE: CWE-134

Severity Category

Insecure Use Scanf Fn

Rule ID: insecure-use-scanf-fn

Description: Avoid using 'scanf()'. This function, when used improperly, does not consider buffer boundaries and can lead to buffer overflows. Use 'fgets()' instead for reading input.

CWE: CWE-676

Severity Category

Insecure Use Strcat Fn

Rule ID: insecure-use-strcat-fn

Description: Finding triggers whenever there is a strcat or strncat used. This is an issue because strcat or strncat can lead to buffer overflow vulns. Fix this by using strcat_s instead.

CWE: CWE-676

Severity Category

Insecure Use String Copy Fn

Rule ID: insecure-use-string-copy-fn

Description: Finding triggers whenever there is a strcpy or strncpy used. This is an issue because strcpy does not affirm the size of the destination array and strncpy will not automatically NULL-terminate strings. This can lead to buffer overflows, which can cause program crashes and potentially let an attacker inject code in the program. Fix this by using strcpy_s instead (although note that strcpy_s is an optional part of the C11 standard, and so may not be available).

CWE: CWE-676

Severity Category

Insecure Use Strtok Fn

Rule ID: insecure-use-strtok-fn

Description: Avoid using 'strtok()'. This function directly modifies the first argument buffer, permanently erasing the delimiter character. Use 'strtok_r()' instead.

CWE: CWE-676

Severity Category

Random Fd Exhaustion

Rule ID: random-fd-exhaustion

Description: Call to 'read()' without error checking is susceptible to file descriptor exhaustion. Consider using the 'getrandom()' function.

CWE: CWE-774

Severity Category

Use After Free

Rule ID: use-after-free

Description: Variable '$VAR' was used after being freed. This can lead to undefined behavior.

CWE: CWE-416

Severity Category

Ship Fast. Validate Smarter.Protect your reputation.

Cyclopt G2 profile

29A, Ptolemaion Street, Coho Building, Thessaloniki, Greece, Tel: +30 2310 471 030
Copyright © 2026 Cyclopt