CLion 2024.2 Help

Inspection: Argument selection defects

When you call a function with several parameters of the same type, you can accidentally swap them and therefore encounter errors that might be difficult to debug. The Argument Selection Defects inspection helps you reveal and quick-fix such errors without even compiling your code (the original heuristic algorithm can be found in this research paper):

Argument Selection Defects inspections in the editor

This inspection is enabled by default. You can configure its severity and scope, or turn the inspection off in the Inspection settings dialog (choose C/C++, General, Argument selection defects).

Functionality scope

The Argument Selection Defects inspection detects when two or more arguments of the same type are passed to the function in the wrong order. For such cases, the inspection can process any type, including a user-defined one. Besides, the inspection is typo-tolerant, so the arguments do not have to be exactly the same.

Restrictions

To avoid false positives, the Argument Selection Defects inspection does not warn you when:

  • the function is recursive

  • the presumably swapped arguments are variadic, for example:

    void f(int left, ...); void b(int left, int right) { f(right, left); }
  • the function or parameter names contain the following substrings: swap, reverse, inverse, flip, backward, or rotate

  • the argument names are shorter than three symbols (like x, y, ab)

  • the function is called multiple times with the same arguments being passed in different order, for instance:

    case LANDSCAPE: bitmap = new Bitmap (width , height); break ; case PORTRAIT: bitmap = new Bitmap (height , width); ...
Last modified: 26 May 2024