主要内容

Cpp.Function Class

Namespace: Cpp
Superclasses: ObjectWithPosition

Represents a function in your code

Since R2026a

Description

Function class represents the various types of functions in your code. This class inherits from the class ObjectWithPosition. You can use the predicates associated with this class and the base class with objects of this object.

Predicates

expand all

Examples

collapse all

  1. In a new folder Function, initialize a new coding standard. At the command line, enter:

    polyspace-query-language init

  2. In the file main.pql, enter this content:

    package main
    
    // Main PQL file defines the catalog of your PQL project.
    // The catalog is a collection of sections.
    catalog FunctionExample = {
    	#[Description("Example Section")]
    	section ExampleSection = {
    		#[Description("Noninlined Function Defined in header"),Id(myRule)]
    		rule ExampleRule = {
    			defect Exampledefect =
    			when            
    				Cpp.Function.is(&func)
    				and func.isDefined()
    				and not func.isInline()
    				and func.extension(&ext)
    				and ext == ".h"
    			raise "Noninline function defined in header file"
    			on func
    		}
    	}
    }

  3. Create the coding standard Function.pschk using this command at the command line:

    polyspace-query-language package

  4. Using the generated coding standard, run a Bug Finder analysis on your source file. Foe example, at the command line, enter:

    polyspace-bug-finder -sources src.h -lang cpp -checkers-activation-file Function.pschk
    The analysis reports a defect on the nonlined function add() in the header file.

Version History

Introduced in R2026a