CLion 2018.2 Help

Inspection in Detail: 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):

cl asd inspection

In CLion, 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).

In order to use the inspection, make sure to enable clangd errors and warnings and clang-tidy via clangd in the Clangd settings.

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.


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: 10 August 2018