Repository navigation
Fix double counting in constexpr call depth [GH #178]
#244
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| fe_only -DTEST_NUMBER=1 --c++17 --max_depth_constexpr_call=300 Test_name.c | ||
| "Test_name.c", line 11: error: expression must have a constant value | ||
| static_assert(f(300) == 300, ""); | ||
| ^ | ||
| "Test_name.c", line 11: note: expression not folded to a constant due to excessive constexpr function call complexity | ||
| static_assert(f(300) == 300, ""); | ||
| ^ | ||
|
|
||
| 1 error detected in the compilation of "Test_name.c". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| fe_only -DTEST_NUMBER=1 --c++17 --max_depth_constexpr_call=300 Test_name.c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| //type:fn | ||
| //options_all:--c++17 --max_depth_constexpr_call=300 | ||
|
|
||
| // Companion to gh-178.sft.cpp: a call in an argument no longer counts as | ||
| // nested in the call it is passed to, but the depth limit is still enforced. | ||
|
|
||
| constexpr int add(int a, int b) { return a + b; } | ||
| constexpr int f(int n) { return n == 0 ? 0 : add(1, f(n - 1)); } | ||
|
|
||
| // 301 nested calls of f: one call too many, still beyond the limit. | ||
| static_assert(f(300) == 300, ""); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //type:fp | ||
| //options_all:--c++17 --max_depth_constexpr_call=300 | ||
|
|
||
| // A constexpr call that appears in an argument of another constexpr call is | ||
| // evaluated before that other call is entered, so it is not nested in it. | ||
| // Previously, the interpreter charged the outer call against the call depth | ||
| // limit before evaluating its arguments, so each level of recursion below | ||
| // counted twice and only about half the requested depth was available. | ||
|
|
||
| constexpr int add(int a, int b) { return a + b; } | ||
| constexpr int f(int n) { return n == 0 ? 0 : add(1, f(n - 1)); } | ||
| static_assert(f(256) == 256, ""); // Previously not a constant. | ||
| static_assert(f(299) == 299, ""); // 300 nested calls of f: at the limit. | ||
|
|
||
| struct S { | ||
| int v; | ||
| constexpr S(int x) : v(x) {} | ||
| }; | ||
| constexpr int g(int n) { return n == 0 ? 0 : S(1 + g(n - 1)).v; } | ||
| static_assert(g(299) == 299, ""); // Previously not a constant. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.