Skip to contentSkip to conversation

c++ scope resolution operator

cocci Sam Tygier 3 participants 5 messages Mar 8 – Mar 9

lore
Share & tools
lore

Sam Tygier

author
#0 lore raw

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

#1 lore raw
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.0

Thanks,
Sam

author
#2 lore raw
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

#4 lore raw
In reply to Sam Tygier
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++.