Skip to content

Assert [[noreturn]] for Log::Fatal to avoid compiler warnings about "sometimes uninitialized" - #418

Merged
andrewherren merged 2 commits into
StochasticTree:mainfrom
MichaelChirico:patch-3
Oct 5, 2026
Merged

andrewherren merged 2 commits into
StochasticTree:mainfrom
MichaelChirico:patch-3

Conversation

@MichaelChirico

Copy link
Copy Markdown
Contributor

clang flags e.g. here under -Wsometimes-uninitialized:

StochTree::ModelType model_type;
if (leaf_model_int == 0) model_type = StochTree::ModelType::kConstantLeafGaussian;
else if (leaf_model_int == 1) model_type = StochTree::ModelType::kUnivariateRegressionLeafGaussian;
else if (leaf_model_int == 2) model_type = StochTree::ModelType::kMultivariateRegressionLeafGaussian;
else if (leaf_model_int == 3) model_type = StochTree::ModelType::kLogLinearVariance;
else if (leaf_model_int == 4) model_type = StochTree::ModelType::kCloglogOrdinal;
else StochTree::Log::Fatal("Invalid model type");

That's because the compiler can't tell that Log::Fatal will always throw std::runtime_error(). Using [[noreturn]] is the standard approach here.

https://en.cppreference.com/cpp/language/attributes/noreturn

@andrewherren
andrewherren merged commit 274f9fb into StochasticTree:main Oct 5, 2026
16 checks passed
dwachsmuth added a commit to Curbcut/nashtree that referenced this pull request Nov 12, 2026
Ports StochasticTree/stochtree StochasticTree#417, StochasticTree#418, StochasticTree#420, StochasticTree#421 and the
exact-posterior MCMC test from StochasticTree#431. The cloglog active-forest
initializer no longer reads an uninitialized starting value; seeded
draws are bitwise unchanged. The Eigen 5 upgrade is deliberately not
ported (see NASH-FORK.md).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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