Skip to content

add in-class initializers to primitive fields - #689

Merged
Joseph Borodach (JosephBorodach) merged 7 commits into
mainfrom
pod-initializers-followup
Aug 10, 2026
Merged

add in-class initializers to primitive fields#689
Joseph Borodach (JosephBorodach) merged 7 commits into
mainfrom
pod-initializers-followup

Conversation

@JosephBorodach

@JosephBorodach Joseph Borodach (JosephBorodach) commented Jul 22, 2026

Copy link
Copy Markdown
Member

Add in-class initializers to primitive fields across all remaining POD types in the SDK

Why

Followup to #687, which fixed Camera::properties only. Same footgun exists in every other POD carried over gRPC

@acmorrow

Copy link
Copy Markdown
Member

I want to think about this one for a bit

@acmorrow

Copy link
Copy Markdown
Member

Joseph Borodach (@JosephBorodach) - I spent some time musing about this. As an old-school high-performance C++ type, my initial reaction was that I didn't like the idea. Basically, by giving these types non-static data-member initializers, they are no longer trivial types. So, for instance, it is no longer free to allocate an array of them, because now each one needs initialization. From there, I'd have argued that users who write, for instance, struct pose instead of struct pose{} have written a bug. My preference would have been that we relied on tooling to catch the bugs, rather than penalizing all uses of these types.

However, practical considerations I think rule the day the other way, in favor of your change.

  • The only tooling that actually catches this is MSAN, which requires instrumentation all the way through the C++ runtime library, which is impractical. Static analysis tools and -W[maybe-]uninitialized either do not reliably catch misuse, are plagued with false positives, or both.
  • While C++ SDK authors can probably be held to the standard of knowing the difference between pose and pose{} and when to use each, it is probably not reasonable to hold module authors to that level of rigor. Since the types you are changing here are the user vocabulary types, and not the wire types, they should have good user facing ergonomics.
  • Future versions of the standard lean toward what you are doing here, along the lines of -ftrivial-auto-var-init=zero and future C++ standards evolution (see P2795).

So, having thought about it and done some research, I'm somewhat reluctantly in favor. I will take a pass through the changes themselves to see if any of them require more thought.

@JosephBorodach

Copy link
Copy Markdown
Member Author

Thanks for taking the time to think it through Andrew C. Morrow (@acmorrow) - the tradeoff you're weighing is the right one, and I appreciate you landing on the ergonomics side despite the triviality cost.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I'd like lia (@lia-viam) to take a second look in case any of the defaults have semantics I'm not aware of.

@viam-overwatch

viam-overwatch Bot commented Aug 6, 2026

Copy link
Copy Markdown

Hey Joseph Borodach (@JosephBorodach) — this PR has been approved and CI has been green for 3+ business days. Ready to merge?

Auto-comment from overwatch. Will not re-nudge for 7 days.

Comment thread src/viam/sdk/components/audio_in.hpp Outdated
std::chrono::nanoseconds start_timestamp_ns;
std::chrono::nanoseconds end_timestamp_ns;
int sequence_number; // sequential chunk number
std::chrono::nanoseconds start_timestamp_ns = std::chrono::nanoseconds::zero();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this not just be = {} ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch and it's more consistent with the other defaults in this PR. Updating

@JosephBorodach
Joseph Borodach (JosephBorodach) merged commit 04854f3 into main Aug 10, 2026
5 checks passed
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.

3 participants