Skip to content

Mutating operations are const methods on Database (const-correctness lie) #26

Description

@jkalias

Problem

Database::Instance() returns std::shared_ptr<const Database> (src/database.cc:108), yet the mutating operations Save, SaveAutoIncrement, Update, and Delete (include/database.h) are declared const and are therefore callable through that pointer-to-const even though they modify the underlying database.

Note: this issue originally said Instance() returns const Database&; PR #28 changed the return type to std::shared_ptr<const Database>. That does not resolve the issue — it arguably reinforces it, since every caller now holds a handle to a const Database and can still mutate persistent state through it.

Impact

Mechanically harmless (the SQLite handle is mutated through a sqlite3* member, which const doesn't protect), but the API misrepresents intent: a handle to const appears read-only while it can mutate persistent state. This is a design/maintainability smell and can mislead callers reasoning about thread-safety and aliasing.

Suggested direction

Either make the mutators non-const and have Instance() hand out a non-const handle for write access (possibly a separate const accessor for read-only use), or, if the const-singleton pattern is intentional, document the rationale explicitly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions