-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Wrong evaluation of a if constexpr requires
#63845
Comments
@llvm/issue-subscribers-clang-frontend |
I believe this should be ok, |
In foo, Ultimately, the comment "If length could be evaluated at compile time" is what does not work here, function parameters are never constant expressions. Now, the thing I'm not quite sure about is whether we should diagnose L19 in the requires or not? Presumably not, and if so I don't think there is a bug there. I'm not quite sure what GCC and MSVC are doing, am I missing something? |
Yeah, I believe @cor3ntin is correct we can't return the int main() {
auto x = foo(get_length(std::vector<int>(5)));
x.resize(1); // array does not have resize
//constexpr auto y = foo(get_length(std::array<int, 3>()));
static_assert( foo(get_length(std::array<int, 3>())).size() == 3 ); // in Clang y is vector?
} I think clang is correct here although the diagnostic could be way more informative. CC @tbaederr |
@shafik the salient difference https://gcc.godbolt.org/z/vcdr7nea7 |
Consider the following, which is simplified to just the essentials (https://gcc.godbolt.org/z/774n7svhn):
clang disagrees with gcc/msvc about whether the first example is valid. For the second and third examples, clang agrees with gcc/msvc that an error shouldn't be printed. Comparing the second and third examples, though, shows that clang isn't consistent with itself. Somehow, whether a local variable is type-dependent changes the result of the "if constexpr", which is pretty clearly wrong. |
Even more simplified code:
Online demo: https://gcc.godbolt.org/z/j6Mnqjvbz Another simplified example without function template:
Online demo: https://gcc.godbolt.org/z/zGfo9a45P Related discussion: https://stackoverflow.com/q/76697099/7325599 |
@erichkeane you have an opinion on this? |
I think Clang is wrong here, see the answer in @Fedr 's last stack overflow example. I think we're being overly aggressive with the 'local variable' check. |
This patch picks up #78598 with the hope that we can address such crashes in `tryCaptureVariable()` for unevaluated lambdas. In addition to `tryCaptureVariable()`, this also contains several other fixes on e.g. lambda parsing/dependencies. Fixes #63845 Fixes #67260 Fixes #69307 Fixes #88081 Fixes #89496 Fixes #90669 Fixes #91633
The following program
is accepted by GCC and MSVC. But in Clang
y
is astd::vector
for some reason. Online demo: https://gcc.godbolt.org/z/h53zc3bjvRelated discussion: https://stackoverflow.com/a/76673819/7325599
Could you please check?
The text was updated successfully, but these errors were encountered: