주요 콘텐츠

Cpp.SourceLoc Class

Namespace: Cpp

Query the cast related information in your code

Since R2026a

Description

Cast package allows you to check various cast related issues in your code

Predicates

expand all

Examples

collapse all

  1. In a new folder SourceLoc, 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 SourceLocExample = {
        #[Description("Example Section")]
        section ExampleSection = {
            #[Description("Macro definition repreated in multiple header files"),Id(myRule)]
            rule ExampleRule = {
                defect Exampledefect =
                when Cpp.SourceLoc.someSourceFile(&SourceFile)
                and SourceFile.pathExtension(&str)
                and str != ".cpp"
                raise "Source file extension: \"{str}\""
                on SourceFile
            }
        }
    }
    

  3. Create the coding standard SourceLoc.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.cpo -lang cpp -checkers-activation-file SourceLoc.pschk
    The analysis reports defects on C++ source files that has extensions other than .cpp.

Version History

Introduced in R2026a