Skip to content

Use anonymous namespaces for private functions in C++ files #591

Description

@arcondello

Turns out just because a function is only defined in a .cpp file, doesn't mean that it is private. E.g., I added

// flow.hpp
int namespace_experiment(int a) {
    return a;
}

and then

// 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

// 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 #590 which prompted me to learn more about it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions