dwavesystems / dwavesystems/dwave-optimization
Use anonymous namespaces for private functions in C++ files
- Dominant language
- C++
- Stars
- 31
- Forks
- 36
- Avg merge
- 16h 55m
- Merged PRs (30d)
- 8
Description
Turns out just because a function is only defined in a `.cpp` file, doesn't mean that it is private. E.g., I added
```c++
// flow.hpp
int namespace_experiment(int a) {
return a;
}
```
and then
```c++
// test_flow.cpp
int namespace_experiment(int a);
```
and that works just fine despite the declaration not being in the corresponding header, but rather an unrelated one.
But adding
```c++
// flow.hpp
namespace {
int namespace_experiment(int a) {
return a;
}
}
```
correctly makes it private.
We should fix this everywhere.
#### AI Generation Disclosure
I found this out when Claude used an anonymous namespace in https://github.com/dwavesystems/dwave-optimization/pull/590 which prompted me to learn more about it.
Contributor guide
Research direction
Start by inspecting the C++ source files for functions defined only in .cpp files, using flow.hpp and test_flow.cpp as the example of the visibility issue. Identify file-local functions that lack anonymous namespaces and update the affected files; the work is done when private functions are consistently restricted across the project and the existing tests still pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100