Datatype detection

CC4M attempts to derive the datatypes of the variables created in the code that is checked. However, this analysis is imperfect and therefore unexpected results may be encountered. This section provides a non-exhaustive overview of the situations in which variables are detected as objects of a specific class. This information allows CC4M to distinguish objects from structs, which is used in multiple checks.

  • The first input of a non-static method.

  • The first output of a constructor in a classdef file.

  • The first output of a non-MATLAB-installed constructor call and the variable was not defined earlier.

  • The output of a selection of MATLAB-installed functions returning an object. This means outputs of for example figure and waitbar are treated as objects if the MATLAB-isntalled version is not shadowed.

  • The target of a subscript assignment like obj = objs(idx) where objs was detected as an object before.

  • An input of a local or nested function and the data types of the inputs of all calls to that function are the same.

  • The output of a call to empty, copy or copyobj (if the input datatype is known). For example: obj = tools.MyClass.empty(); or newObj = copy(obj);