[cocci] c++ scope resolution operator

Sam Tygier <[email protected]> Sun, 8 Mar 2026 21:40:10 +0000
Newsgroups fr.inria.cocci
Message-ID <[email protected]>
Hi,

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

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