Skip to content

Add static_assert to get*, remove to reject non-pk arguments at compile time #1486

Open
Alvov1 wants to merge 2 commits into
fnc12:devfrom
Alvov1:feature/static-assert-get-pk-only
Open

Add static_assert to get*, remove to reject non-pk arguments at compile time #1486
Alvov1 wants to merge 2 commits into
fnc12:devfrom
Alvov1:feature/static-assert-get-pk-only

Conversation

@Alvov1

@Alvov1 Alvov1 commented Jun 2, 2026

Copy link
Copy Markdown

What

get(), get_pointer(), get_optional(), get_no_throw() and remove() silently accepted any Ids..., including query expressions like where(...). This compiled fine but crashed at runtime with a cryptic std::system_error.

Now passing a non-bindable type produces a clear compile-time error:

error: static assertion failed: Only primary key values are accepted as Ids

How

Added static_assert((is_bindable_v<Ids> && ...), ...) to get, get_pointer, get_optional and remove. get_no_throw is not checked directly — it delegates to get_pointer, which already has the assert.

Tests

Extended tests with tests/static_tests/get_pk_ids.cpp that validates all five functions with STATIC_REQUIRE (positive cases only)

Closes #1485

Alvov1 added 2 commits June 2, 2026 20:24
Added static_assert in get, get_pointer, get_optional and remove
to produce a clear compile-time error when non-bindable types (e.g. where())
are passed as Ids, instead of a runtime crash.

Changes are applied in dev/storage.h; include/sqlite_orm/sqlite_orm.h
is the regenerated amalgamation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant