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.
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.
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.
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.
assert(x++ > 0);
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.
int i = 0;
while (i < 10)
Process();
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.
template <typename T>
void Forward(T&& value) {
auto copy = std::move(value);
}
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.
char c = input[0];
bool valid = isalpha(c);
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.
int values[100];
int* ptr = values;
size_t n = sizeof(ptr) / sizeof(int);
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.
std::unique_lock<std::mutex> lock(mutex);
cv.wait(lock);
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.
std::string name = "abc";
std::memcpy(&other, &name, sizeof(name));
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.
std::scoped_lock<std::mutex>;
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.
std::string source = "hello";
auto moved = std::move(source);
Use(source);
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.
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.
for (int i = 0; i < 10; i++) {
if (bad)
goto exit;
Process(i);
}
exit:
return;
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.
double total = price * 0.08;
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.
int count;
std::cin >> count;
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.
// a.cpp
int value = ReadConfig();
// 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.
int count = 3.14;
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).
int* values = static_cast<int*>(std::malloc(n * sizeof(int)));
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.
int* CreateArray(std::size_t n) {
return new int[n];
}
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).
double result = (double)value / count;
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.
class Account {
int balance;
public:
Account() {}
};
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.
int* address = reinterpret_cast<int*>(raw);
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.
union Value {
int i;
float f;
};
Value v;
v.f = 1.5f;
Use(v.i);
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.
Base base = derived;
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.
class Buffer {
public:
~Buffer();
Buffer(const Buffer&);
Buffer& operator=(const Buffer&);
};
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.
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.
for (auto item : items)
Process(item);
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.
for (int i = 0; i < items.size(); i++)
Process(items[i]);
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.
std::string message = "User: ";
message = message + name + ", id=" + id;
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.
std::vector<int> values;
for (int i = 0; i < 1000; i++)
values.push_back(i);
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.
const std::string name = "abc";
auto copy = std::move(name);
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.
class Buffer {
public:
Buffer(Buffer&& other) {}
};
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.
class Config {
public:
~Config() {}
};
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.
Widget widget = CreateWidget();
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.
void SetName(std::string name);
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.
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.
if (ready)
Process();
Finalize();
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.
const int GetValue();
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.
if (items.size() == 0)
return;
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.
class Utility {
public:
int Square(int n) { return n * n; }
};
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.
if (ptr != nullptr)
delete ptr;
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.
if (valid) {
return value;
} else {
return 0;
}
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.
void Validate(const Request& r) {
if (r.A) {
if (r.B) {
if (r.C) {
Process(r);
}
}
}
}
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.
for (int i = 0; i < size; i++)
Process(i);
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.
if (count)
Process();
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.
int width = 10, height = 20;
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.
class Account {
int balance = 0;
public:
int GetBalance() { return balance; }
};
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.
if (ready)
Process();
Finalize();
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.
void SetTimeout(int);
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.
void Print(const std::string& s, std::size_t* size);
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.
class Config {
public:
int retries;
public:
int timeout;
};
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.
void Process(bool done) {
if (done) {
Finalize();
}
return;
}
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.
int count;
count = ComputeCount();
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.
int result = (*callback)(value);
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.
std::unique_ptr<Widget> widget;
widget.get()->Render();
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.
std::string text = "hello";
Accept(text.c_str());
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.
std::string name = "";
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).
return value > 0 ? true : false;
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.
int value = ptr[0];
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.
Logger logger;
logger.Log("message");
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.
if (text.compare("done") == 0)
Finalize();
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.
std::unique_ptr<Widget> widget = Create();
delete widget.release();
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.
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.
auto handler = std::bind(&App::OnClick, this, std::placeholders::_1);
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>).
#include <stdlib.h>
#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.
for (std::size_t i = 0; i < items.size(); i++)
Process(items[i]);
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.
std::shared_ptr<Widget> widget(new Widget());
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.
std::unique_ptr<Widget> widget(new Widget());
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.
void SetName(const std::string& name) {
this->name = name;
}
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.
std::string pattern = "a\\d+\\s*b";
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.
int GetValue(void);
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.
std::pair<int, int> GetBounds() {
return std::pair<int, int>(0, 100);
}
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.
std::vector<int> values;
std::vector<int>(values).swap(values);
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.
static_assert(sizeof(int) == 4, "int must be 4 bytes");
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.
std::vector<int> values;
std::vector<int>::iterator it = values.begin();
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.
bool valid = 1;
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.
class Config {
int retries;
public:
Config() : retries(3) {}
};
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.
class Buffer {
public:
~Buffer() {}
};
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.
class NonCopyable {
private:
NonCopyable(const NonCopyable&);
};
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]].
int GetCount();
[[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.
int GetSize() { return size; }
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.
int* ptr = NULL;
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.
class Derived : public Base {
public:
void Draw();
};
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.
std::map<std::string, int, std::less<std::string>> lookup;
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.
bool hasActive = std::uncaught_exception();
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.
typedef unsigned int uint;
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.
Miscellaneous Issue
Rule ID: misc-*
Description: Code pattern that may indicate a problem.
Code pattern that may indicate a problem.
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.
int value = 42;
int& ref = value;
Use(ref);
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.
// helper.h
int Square(int n) { return n * n; }
// 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.
int const* ptr;
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.
int Factorial(int n) {
return n * Factorial(n - 1);
}
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.
class Account {
public:
int balance;
};
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).
if (ready && ready)
Process();
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.
assert(sizeof(int) == 4);
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.
try {
throw std::runtime_error("failed");
} catch (std::runtime_error error) {
Handle(error);
}
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).
class Widget {
public:
void operator=(const Widget& other) { /* ... */ }
};
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.
std::unique_ptr<Widget> widget;
widget.reset(widget.release());
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.
using StringList = std::vector<std::string>;
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.
void Handle(int eventId, int unusedCode);
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.
using std::string;
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.
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
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.
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
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
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
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
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
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
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
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
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
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
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
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
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
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


