Files
llvm-tms34010/clang/test/CodeGenCXX/bad-codegen-for-constexpr-structured-bindings.cpp
Matthias Wippich 27249aa2d8 [clang] Implement CWG3135 - constexpr structured bindings with prvalues from tuples (#191880)
This patch implements
[CWG3135](https://cplusplus.github.io/CWG/issues/3135.html). This has
been accepted into C++26 at the Croydon meeting through [CWG Motion
3](https://github.com/cplusplus/draft/issues/8824).

This change has not been designated a defect report. However, there was
recently some discussion about this designation and GCC implements it as
DR. Therefore, this is treated as DR regardless.
2026-05-21 22:16:40 +08:00

41 lines
1023 B
C++

// RUN: %clang_cc1 -std=c++26 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
namespace std {
using size_t = decltype(sizeof(0));
template <typename T> struct tuple_size;
template <size_t I, typename T> struct tuple_element;
template <typename T> struct tuple_size<const T> : tuple_size<T> {};
template <size_t I, typename T> struct tuple_element<I, const T> {
using type = const typename tuple_element<I, T>::type;
};
} // namespace std
using u8 = unsigned char;
template <u8 N> struct Range {
template <std::size_t I>
constexpr friend u8 get(Range) noexcept {
return I;
}
};
namespace std {
template <u8 N> struct tuple_size<Range<N>> {
static constexpr std::size_t value = N;
};
template <std::size_t I, u8 N> struct tuple_element<I, Range<N>> {
using type = u8;
};
} // namespace std
const u8 &f() {
static constexpr auto [I] = Range<1>();
return I;
}
// CHECK: @[[TMP:_ZZ1fvE1I]] = internal constant i8 0, align 1
// CHECK-LABEL: define {{.*}} @_Z1fv(
// CHECK: ret ptr @[[TMP]]