I was wondering whether it is somehow possible to get a loop into a expression so I can use it directly in a static_assert() (and it would be interpreted directly rather than compiled to bytecode).
Details
Diff Detail
Event Timeline
clang/test/AST/Interp/loops.cpp | ||
---|---|---|
93 | Can you also add some tests that use nested loops with multiple levels of break and continue use? Also, I think it might be useful to show the jump statements causing code to be an invalid constant expression, as in: constexpr int foo() { int i; do { break; i = 12; } while (1); return i; } constexpr int f = foo(); |
clang/test/AST/Interp/loops.cpp | ||
---|---|---|
93 | I can add a commented-out test case for that, but it is currently being rejected for the wrong reasons. I investigated that in another case already and it will simply be rejected because the variable declaration does not have an initializer. Not because we're reading an uninitialized variable. |
clang/test/AST/Interp/loops.cpp | ||
---|---|---|
10 | infinite loop w/o a side effect are undefined behavior and so should be ill-formed and generate a diagnostic e.g. while(1);, so we should check these cases. |
clang/test/AST/Interp/loops.cpp | ||
---|---|---|
10 | I think that's better done with a more general approach that limits the iteration count for all loops like the current interpreter does. But that would probably blow up this patch too much. Unfortunately I can't add test case for the case you describe because the clang process with the new interpreter would never terminate :) Can add a commented-out version though. |
clang/test/AST/Interp/loops.cpp | ||
---|---|---|
10 | I think that is fine approach for now. |