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
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