Skip to content

Should asserts in const expressions always be evaluated? #447

Closed
@leafpetersen

Description

@leafpetersen

A question was raised as to whether asserts in const expressions should always be evaluated, or only when asserts are otherwise enabled. Note that the notion of "asserts are otherwise enabled" is not necessarily well-defined at the point that consts are evaluated if we allow turning assertions on and off dynamically. In discussion, it seems useful to allow normal assertions to be:

  • stripped out/not stripped out during compilation
  • if not stripped out, turned on/turned off at runtime

Since consts are evaluated at compiled time, the only way we could turn const asserts on/off would be via the compile time control. That implies that we would only not evaluate const asserts if the compile time flag was off.

If we allow the compile time flag to turn off const assertions, then in table form the behavior looks like this:

runtime flag on runtime flag off
compile flag on const + normal const only
compile flag off none none

If we always evaluate const asserts, then the behavior looks like this:

runtime flag on runtime flag off
compile flag on const + normal const only
compile flag off const only const only

I don't see a lot of value in not evaluating const asserts. I also suspect that the analyzer always evaluates them: @stereotype441 is that correct?

So my inclination would be to go with the second behavior, where const asserts are always evaluated. The implementations are going with this behavior for now, since it is simpler to implement. If we decide to require the ability to turn on/off const asserts they can add this later as a non-breaking change.

cc @lrhn @munificent @eernstg @mraleph @a-siva

Metadata

Metadata

Assignees

Labels

enhanced-constRequests or proposals about enhanced constant expressions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions