주요 콘텐츠

Cpp.Norm Class

Namespace: Cpp

Contains predicates that check if a keyword is a C or C++ keyword

Since R2026a

Description

The PQL class Norm allows you to check if a Polyspace Query Language (PQL) string object contains a C or C++ keyword. This card does not represent a syntax node and does not define a PQL type.

Predicates

expand all

Examples

Check If C++ Keywords are Redefined

Consider this C/C++ code that redefines keywords:


#define class my_class   // Preprocessor replaces 'class' tokens with 'my_class'

#define int my_int // Preprocessor replaces 'int' tokens with 'my_int'

#define ADD(a, b) ((a) + (b))

To detect preprocessor definitions that redefine C++23 keywords, define this defect:

defect mydefect =
when
   Cpp.PreprocDef.is(&preproc)
   and preproc.name(&name)
   and name.nodeText(&str)
   and Cpp.Norm.isCpp23Keyword(str)
   raise "C++23 keyword redefined in macro: \"{str}\""
   on name
The defct reports a violation on the macros class and int.

Version History

Introduced in R2026a