Skip to content

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

Open
MichaelChirico wants to merge 1 commit into
StochasticTree:mainfrom
MichaelChirico:patch-3
Open

Assert [[noreturn]] for Log::Fatal to avoid compiler warnings about "sometimes uninitialized"#418
MichaelChirico wants to merge 1 commit 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

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