Skip to content

P2809R3 Trivial infinite loops are not Undefined Behavior #6894

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

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.

@jensmaurer jensmaurer force-pushed the motions-2024-03-cwg-6 branch from 8b2cd0e to 42d4196 Compare March 25, 2024 11:13
@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 force-pushed the motions-2024-03-cwg-6 branch from b651734 to 29fcc1c Compare April 15, 2024 22:26
@tkoeppe tkoeppe merged commit cc1f872 into main Apr 15, 2024
@jensmaurer jensmaurer deleted the motions-2024-03-cwg-6 branch June 30, 2024 11:30
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.

[2024-03 CWG Motion 6] Trivial infinite loops are not Undefined Behavior P2809 R3 Trivial infinite loops are not Undefined Behavior
3 participants