[libcxx-commits] [PATCH] D155064: [clang][SemaCXX] Diagnose tautological uses of consteval if and is_constant_evaluated
Sam McCall via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Sep 27 09:39:49 PDT 2023
sammccall added a comment.
Hi, I'm afraid this breaks valid code with false diagnostics, I need to revert.
Specifically it complains about missing lambda captures for values that are in fact arguments to the lambda:
template <typename F>
constexpr void inner(F f) {
return f(0);
}
template <typename F>
void outer(F f) {
inner([](auto I) {
constexpr auto kFuncs = [](F& g) { return g(); };
(void) kFuncs;
});
}
void entry() {
outer([&] {});
}
$ bin/clang++ -fsyntax-only ~/test.cc
/usr/local/google/home/sammccall/test.cc:9:47: error: variable 'g' cannot be implicitly captured in a lambda with no capture-default specified
9 | constexpr auto kFuncs = [](F& g) { return g(); };
| ^
/usr/local/google/home/sammccall/test.cc:9:29: note: while substituting into a lambda expression here
9 | constexpr auto kFuncs = [](F& g) { return g(); };
| ^
/usr/local/google/home/sammccall/test.cc:3:10: note: in instantiation of function template specialization 'outer((lambda at /usr/local/google/home/sammccall/test.cc:15:9))::(anonymous class)::operator()<int>' requested here
3 | return f(0);
| ^
/usr/local/google/home/sammccall/test.cc:8:3: note: in instantiation of function template specialization 'inner<(lambda at /usr/local/google/home/sammccall/test.cc:8:9)>' requested here
8 | inner([](auto I) {
| ^
/usr/local/google/home/sammccall/test.cc:15:3: note: in instantiation of function template specialization 'outer<(lambda at /usr/local/google/home/sammccall/test.cc:15:9)>' requested here
15 | outer([&] {});
| ^
/usr/local/google/home/sammccall/test.cc:9:35: note: 'g' declared here
9 | constexpr auto kFuncs = [](F& g) { return g(); };
| ^
/usr/local/google/home/sammccall/test.cc:9:29: note: lambda expression begins here
9 | constexpr auto kFuncs = [](F& g) { return g(); };
| ^
/usr/local/google/home/sammccall/test.cc:9:30: note: capture 'g' by value
9 | constexpr auto kFuncs = [](F& g) { return g(); };
| ^
| g
/usr/local/google/home/sammccall/test.cc:9:30: note: capture 'g' by reference
9 | constexpr auto kFuncs = [](F& g) { return g(); };
| ^
| &g
/usr/local/google/home/sammccall/test.cc:9:30: note: default capture by value
9 | constexpr auto kFuncs = [](F& g) { return g(); };
| ^
| =
/usr/local/google/home/sammccall/test.cc:9:30: note: default capture by reference
9 | constexpr auto kFuncs = [](F& g) { return g(); };
| ^
| &
1 error generated.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D155064/new/
https://reviews.llvm.org/D155064
More information about the libcxx-commits
mailing list