cpp_parsing_pref
- Value
as_vardef_with_ctororas_fundef- Default
as_vardef_with_ctor
In C++, foo bar(x); can declare a function bar that takes an x and returns a foo, or define a variable bar of type foo built with the argument x. In a function body, Opengrep reads it as a variable; elsewhere, as in a class body, as a declaration. A pattern has no such context, and this option chooses how a pattern like foo $X(...); is read:
as_vardef_with_ctor: as a variable built with a constructor, which matchesfoo obj(1);in a function body;as_fundef: as a function declaration, which matchesfoo bar(x);in a class body.
Examples
One pattern, two readings
ctor.yaml
rules: - id: foo-ctor pattern: foo $X(...); message: foo $X languages: [cpp] severity: INFO options: cpp_parsing_pref: as_vardef_with_ctor - id: foo-fundef pattern: foo $X(...); message: foo $X languages: [cpp] severity: INFO options: cpp_parsing_pref: as_fundefctor.cpp
class Widget { // ruleid: foo-fundef foo bar(x); void build() { // ruleid: foo-ctor foo obj(1); }};Command and result
$ opengrep test .
2/2: ✓ All tests passed
No tests for fixes found.