mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-05-14 18:06:32 +00:00

(This relands 59337263ab45d7657e and makes sure comma operator diagnostics are suppressed in a SFINAE context.) While at it, add the diagnosis message "left operand of comma operator has no effect" (used by GCC) for comma operator. This also makes Clang diagnose in the constant evaluation context which aligns with GCC/MSVC behavior. (https://godbolt.org/z/7zxb8Tx96) Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D103938
26 lines
851 B
C++
26 lines
851 B
C++
// RUN: %clang_cc1 -std=c++2a -verify %s
|
|
|
|
template<typename ...T, typename ...Lambda> void check_sizes(Lambda ...L) {
|
|
static_assert(((sizeof(T) == sizeof(Lambda)) && ...));
|
|
}
|
|
|
|
template<typename ...T> void f(T ...v) {
|
|
// Pack expansion of lambdas: each lambda captures only one pack element.
|
|
check_sizes<T...>([=] { (void)&v; } ...);
|
|
|
|
// Pack expansion inside lambda: captures all pack elements.
|
|
auto l = [=] { ((void)&v, ...); };
|
|
static_assert(sizeof(l) >= (sizeof(T) + ...));
|
|
}
|
|
|
|
template void f(int, char, double);
|
|
|
|
namespace PR41576 {
|
|
template <class... Xs> constexpr int f(Xs ...xs) {
|
|
return [&](auto ...ys) { // expected-note {{instantiation}}
|
|
return ((xs + ys), ...); // expected-warning {{left operand of comma operator has no effect}}
|
|
}(1, 2);
|
|
}
|
|
static_assert(f(3, 4) == 6); // expected-note {{instantiation}}
|
|
}
|