Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P2809R3 Trivial infinite loops are not Undefined Behavior #6894

Merged
merged 1 commit into from Apr 15, 2024

Conversation

jensmaurer
Copy link
Member

@jensmaurer jensmaurer added this to the post-2024-03 milestone Mar 23, 2024
A \defnadj{trivial infinite}{loop} is a trivially empty iteration statement
for which the converted controlling expression is a constant expression,
when interpreted as a \grammarterm{constant-expression}\iref{expr.const}, and
evaluates to \tcode{true}.
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this "interpreted as a constant-expression" wording mean that the following will be treated as a trivial infinite loop?

(Note that std::is_constant_evaluated() returns true when evaluated in a constant-expression, and false when not manifestly constant-evaluated.)

#include  <type_traits>
int main() {
    while (std::is_constant_evaluated());
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that is a "trivial infinite loop". That means, optimizations are reduced around that loop and each step of the loop execution will call yield. Except that the body of the loop will never actually be executed at runtime.

@tkoeppe tkoeppe force-pushed the motions-2024-03-cwg-6 branch 2 times, most recently from a65cdbc to b651734 Compare April 15, 2024 22:25
@tkoeppe tkoeppe merged commit cc1f872 into main Apr 15, 2024
4 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
3 participants