주요 콘텐츠

Cpp.CallSite Class

Namespace: Cpp
Superclasses: ObjectWithPosition

Represents a function call site

Since R2026a

Description

CallSite class represents the position in your code in which a function is invoked. This class inherits from the class ObjectWithPosition. You can use the predicates associated with this class and its base class to construct queries related to call sites in your C/C++ code.

Predicates

expand all

Examples

collapse all

  1. In a new folder CallSite, 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 CallSiteExample = {
    #[Description("Example Section")]
    	section ExampleSection = {
    #[Description("Virtual function output discarded"),Id(myRule)]
    		rule ExampleRule = {
    			defect Exampledefect =
    			when
    			Cpp.CallSite.is(&callsite)
    			and callsite.extension(&extension)
    			and extension == ".cpp"
    			and callsite.numberOfArguments(&nargs)
    			and nargs > 2
    			and callsite.isVirtual()
    			and callsite.immediatelyDiscarded()
    			and callsite.toString(&str)
    			raise "Result of virtual function with >2 arguments discarded: \"{str}\""
    			on callsite
    
    		}
    	}
    }
    
    

  3. Create the coding standard CallSite.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.cpp -lang cpp -checkers-activation-file CallSite.pschk
    The analysis reports the a defect on the callsite obj->compute.

Version History

Introduced in R2026a