Re: [cocci] c++ scope resolution operator

Julia Lawall <[email protected]> Sun, 8 Mar 2026 22:43:06 +0100 (CET)
Newsgroups fr.inria.cocci
Message-ID <[email protected]>

On Sun, 8 Mar 2026, Sam Tygier wrote:

> Hi,
>
> I am having trouble using Coccinelle with C++ around scope operators, e.g.
> std::cout.

Sorry, but the support for :: is still work in progress.

julia

>
> For example this works as expected (replaces the string):
>
> hello.cpp:
>
> #include <iostream>
> using namespace std;
> int main(){
>     cout << "hello";
>     return 0;
> }
>
> hello.cocci:
>
> @@
> @@
> - cout << "hello";
> + cout << "hello sam";
>
> But the actual I want to work on uses explicit namespace scopes
>
> hello.cpp
>
> #include <iostream>
> int main(){
>     std::cout << "hello";
>     return 1;
> }
>
> hello.cocci
>
> @@
> @@
> - std::cout << "hello";
> + std::cout << "hello sam";
>
> gives an error:
>
> $ spatch --sp-file hello.cocci hello.cpp --c++=17 --debug
> init_defs_builtins: /usr/lib64/coccinelle/standard.h
> -----------------------------------------------------------------------
> processing semantic patch file: hello3.cocci
> with isos from: /usr/lib64/coccinelle/standard.iso
> -----------------------------------------------------------------------
> @@
> @@
> - std::cout << "hello";
> + std::cout << "hello sam";
>
> minus: parse error:
>   File "hello.cocci", line 3, column 6, charpos = 12
>   around = ':',
>   whole content = - std::cout << "hello";
>
> I am using coccinelle from the Fedora package 1.3-3.fc42
>
> $ spatch --version
> spatch version 1.3 compiled with OCaml version 5.3.0
>
>
> Thanks,
> Sam
>
>
>
>