https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101557
--- Comment #5 from Federico Kircheis <federico at kircheis dot it> ---
Today I just found a possible workaround that involves macros and lambdas...
----
struct node {
const char* d;
const node& left;
};
#define LEAF(a) []()-> const node&{ constexpr static auto a = node{"a",Null};
return a; }()
#define NODE(a,b) []()-> const node&{constexpr static auto a = node{"a",b};
return a; }()
constexpr node Null = node{"",Null};
constexpr auto a = node{"a",NODE(a,LEAF(b))};
constexpr auto a2 = node{"a",node{"a", node{"a", Null}}};
constexpr int mysize(const node& n) noexcept{
return (&n == &Null) ? 0 : 1 + mysize(n.left);
}
constexpr auto size0 = mysize(Null);
static_assert(size0 == 0, "");
constexpr auto size3 = mysize(a);
static_assert(size3 == 3, "");
----
"mysize(a)" compiles, while "mysize(a2)" does not, even if the two
datastructures are equivalent
Unfortunately clang does not accept it