[PATCH] D119651: [clang] Fix evaluation context type for consteval function calls in instantiations
Evgeny Shulgin via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 16 12:30:53 PST 2022
Izaron added a comment.
After an investigation in GDB I can say that the assert seems to be wrong. Since Clang instantiates classes and functions "on the fly" where appropriate, we indeed can get a run-time evaluation context after a compile-time evaluation context. I was sure that evaluation contexts were made to represent a clean hierarchy of context, because they're interrelated, but the case with instantiations confuses me.
This code ...
template<int N>
struct good_struct {
// we are in run-time eval context!
static consteval int evalconst() {
// we are in compile-time eval context!
return N * N;
}
void foo();
void bar();
};
//int good_struct_100 = good_struct<100>::evalconst();
//int good_struct_200 = good_struct<200>::evalconst();
consteval int consteval_foo() {
// we are in compile-time eval context!
return good_struct<100>::evalconst();
}
template</* we are in compile-time eval context! */ int N = good_struct<200>::evalconst()>
constexpr int templated_foo() {
return N;
}
... hits the assert two times, unless we uncomment the lines with `good_struct_100` and `good_struct_200`. That's because Clang instantiates the classes when it "sees" them, straight from consteval/template contexts. I couldn't come up with a correct code that breaks though.
I am now less sure if the patch (without the assert) is acceptable, what if the concept of "evaluation contexts" needs a revision?..
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D119651/new/
https://reviews.llvm.org/D119651
More information about the cfe-commits
mailing list