Function declares more than one bool parameter
ID |
c.maintainability.multiple_bool_parameters |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Api Design |
Language |
C / C++ |
Description
This function declares two or more bool parameters. At the call site a bare true/false carries no label, so configure(true, false) gives the reader no way to tell which flag is which without opening the declaration — and it is easy to swap two boolean arguments of the same type without the compiler noticing. Replace the flags with an enum that names each state, or split the function into distinct named variants.
Rationale
This function declares two or more bool parameters. At the call site a bare true/false carries no label, so configure(true, false) gives the reader no way to tell which flag is which without opening the declaration — and it is easy to swap two boolean arguments of the same type without the compiler noticing. Replace the flags with an enum that names each state, or split the function into distinct named variants.
The following code illustrates the pattern detected by this rule:
// FLAGGED: Function declares more than one bool parameter
void configure(int retries, bool verbose, bool dry_run);