From 55c1242657cd004406b42423901d24b65be348c3 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 13:22:02 +0000 Subject: [PATCH] Create rule S2253 Forbidden functions CPP-5857 --- rules/S2253/cfamily/metadata.json | 3 +++ rules/S2253/cfamily/rule.adoc | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 rules/S2253/cfamily/metadata.json create mode 100644 rules/S2253/cfamily/rule.adoc diff --git a/rules/S2253/cfamily/metadata.json b/rules/S2253/cfamily/metadata.json new file mode 100644 index 00000000000..6a414df1368 --- /dev/null +++ b/rules/S2253/cfamily/metadata.json @@ -0,0 +1,3 @@ +{ + "title": "User-specified functions should not be called" +} \ No newline at end of file diff --git a/rules/S2253/cfamily/rule.adoc b/rules/S2253/cfamily/rule.adoc new file mode 100644 index 00000000000..e1adb62926b --- /dev/null +++ b/rules/S2253/cfamily/rule.adoc @@ -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 $ + +[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 +} +---- +