Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create rule S2253 Forbidden functions CPP-5857 #4509

Merged
merged 4 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rules/S2253/cfamily/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"title": "User-specified functions should not be called"
}
25 changes: 25 additions & 0 deletions rules/S2253/cfamily/rule.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
This rule template allows to define rules that ban the call of some functions, for instance functions provided for legacy reasons. It will not prevent calling member functions or macros with the same name.

It comes with two parameters:

* `names` defines a comma-separated list of function names to ban. You can specify a standalone name, in which case the rule will match functions with that name in any namespaces, or a qualified name (for instance, `print` will match `std::print`, but `::print` will not)
* `message` is the message to display when the rule is violated. If you use a `$` in that message, it will be replaced by the name of the function that was called.


=== Noncompliant code example

Given parameters:

* names: f1, ::f2
* message: Don't call $
alejandro-alvarez-sonarsource marked this conversation as resolved.
Show resolved Hide resolved

[source,cpp]
----
void f() {
f1(); // Noncompliant: Don't call f1
my::f1(); // Noncompliant: Don't call f1
f2(); // Noncompliant: Don't call f2
my::f2() // Compliant
}
----

Loading