C & C++

C & C++

Made by DeepSource

Found use of possibly reserved identifier CXX-E2000

Bug risk
Major

Using reserved identifiers can cause conflicts with the compiler or other system libraries, leading to unexpected behavior or compilation errors.

To fix this issue, choose a different identifier that is not reserved by the implementation. It is recommended to follow naming conventions and avoid using names that are reserved by the language or the compiler.

The C and C++ standards reserve the following names for such use: - identifiers that begin with an underscore followed by an uppercase letter; - identifiers in the global namespace that begin with an underscore.

The C standard additionally reserves names beginning with a double underscore, while the C++ standard strengthens this to reserve names with a double underscore occurring anywhere.

Bad Practice

namespace NS {
    void __f(); // Reserved identifier, not allowed in user code
    using _Int = int; // Reserved identifier, not allowed in user code
    #define cool__macro // Reserved identifier, not allowed in user code
}

int _g(); // Reserved identifier, disallowed in global namespace only

Recommended

namespace NS {
    void f(); // Non-reserved identifier, allowed in user code
    using Int = int; // Non-reserved identifier, allowed in user code
    #define cool_macro // Non-reserved identifier, allowed in user code
}

int g(); // Non-reserved identifier, allowed in global namespace