Skip to content

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

Merged
fnc12 merged 2 commits into
fnc12:devfrom
Alvov1:feature/static-assert-get-pk-only
Jun 14, 2026
Merged

Add static_assert to get*, remove to reject non-pk arguments at compile time #1486
fnc12 merged 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.
@fnc12 fnc12 requested a review from trueqbit June 14, 2026 14:29
@fnc12 fnc12 merged commit 19a84fb into fnc12:dev Jun 14, 2026
11 checks passed
@fnc12

fnc12 commented Jun 14, 2026

Copy link
Copy Markdown
Owner

thanks @Alvov1

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.

2 participants