https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116440
Bug ID: 116440
Summary: [C++20] std::tuple<std::tuple<std::any>> does not
compile
Product: gcc
Version: 14.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: tianchengyu at tencent dot com
Target Milestone: ---
The following code (minimized reproduction) does not compile since gcc 14
(tested on 14.1.0 and 14.2.0), also failed on trunk (as of 20240821).
template <typename T>
using TupleTuple = std::tuple<std::tuple<T>>; // can be replaced with
std::tuple<std::tuple<...>> in following code, just to make it shorter.
struct EmbedAny {
std::any content;
};
// Does not compile: struct with only one std::any field
static_assert(std::is_copy_constructible<TupleTuple<EmbedAny>>::value);
// Does not compile: just std::any in nested std::tuple
static_assert(std::is_copy_constructible<TupleTuple<std::any>>::value);
However, if we add anything before the std::any field, it compiles fine (even a
zero-sized array!):
struct EmbedAnyWithZeroSizeArray {
void* pad[0]; // or, e.g. int pad; would also compile
std::any content;
};
// Compiles: add a zero-sized (or any size) field **before** std::any field.
Adding the field after std::any does not work.
static_assert(std::is_copy_constructible<TupleTuple<EmbedAnyWithZeroSizeArray>>::value);
This only fails on gcc 14+ with -std=c++20 or higher. On older gcc versions
with -std=c++20 or gcc 14+ with -std=c++17 it compiles fine.
I also observed that clang trunk failed to compile with similar errors, but
clang 18 works fine, too.
Godbolt sample: https://godbolt.org/z/Gds4ar716