Skip to content

Placate Green Hills compiler with ternary#670

Merged
chiphogg merged 1 commit intomainfrom
chiphogg/ghc-widened-result
Apr 13, 2026
Merged

Placate Green Hills compiler with ternary#670
chiphogg merged 1 commit intomainfrom
chiphogg/ghc-widened-result

Conversation

@chiphogg
Copy link
Copy Markdown
Member

When the Green Hills compiler encounters an if/else branch whose
predicate is known at compile time, it complains about an unreachable
statement. Even if the predicate depends on template parameters (i.e.,
is not a strict constant across all template instantiations), the
policy triggers on any individual instantiations that contain an
unreachable statement.

Leaving aside the wisdom of this policy as it pertains to generic
programming, the fact is that we're stuck with it and we need to keep
the compiler happy.

To fix this instance, we simply use a ternary operator. The ternary is
just the same as an if/else branch, but it's a single statement. In
testing on AV code, this does seem to placate the Green Hills compiler.

When the Green Hills compiler encounters an if/else branch whose
predicate is known at compile time, it complains about an unreachable
statement.  Even if the predicate depends on template parameters (i.e.,
is not a strict constant _across all template instantiations_), the
policy triggers on any _individual_ instantiations that contain an
unreachable statement.

Leaving aside the wisdom of this policy as it pertains to generic
programming, the fact is that we're stuck with it and we need to keep
the compiler happy.

To fix this instance, we simply use a ternary operator.  The ternary is
just the same as an if/else branch, but it's a single statement.  In
testing on AV code, this does seem to placate the Green Hills compiler.
Copy link
Copy Markdown
Contributor

@geoffviola geoffviola left a comment

Choose a reason for hiding this comment

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

The change looks equivalent to what was there before. Hope to see some green hills results soon 😄

@chiphogg chiphogg merged commit 40dd705 into main Apr 13, 2026
27 checks passed
@chiphogg chiphogg deleted the chiphogg/ghc-widened-result branch April 13, 2026 14:07
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