c++ scope resolution operator
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
Quoted 4 lines · Sam Tygier
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
Quoted 66 lines
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.0Thanks,
Sam
Quoted 8 lines · Julia Lawall
Quoted 4 lines · Sam Tygier
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
Thanks, I'll keep an eye out for updates. Is there a github issue for this that I could subscribe to?
Sam
Re: [cocci] Support for C++ scope resolution operator?
Quoted 1 line
Thanks, I'll keep an eye out for updates. Is there a github issue for this that I could subscribe to?
Not directly for the mentioned functionality so far.
See also:
* Support C++ codebases
2010-12-05
https://github.com/coccinelle/coccinelle/issues/1
* C++
2021-04-15
https://gitlab.inria.fr/coccinelle/coccinelle/-/issues/22
Regards,
Markus
Quoted 8 lines · Sam Tygier
On 08/03/2026 21:43, Julia Lawall wrote:
On Sun, 8 Mar 2026, Sam Tygier wrote:
Hi,
Quoted 8 lines
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
Thanks, I'll keep an eye out for updates. Is there a github issue for this that I could subscribe to?
No, it's part of an ongoing attempt to support c++.