https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100894
Bug ID: 100894
Summary: The std::common_reference implementation seems to be
wrong
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: hewillk at gmail dot com
Target Milestone: ---
In [meta#trans.other-6.3.1], the standard specifies "If T1 and T2 are reference
types and COMMON-REF(T1, T2) is well-formed, then the member typedef type
denotes that type", where COMMON-REF is defined in [meta#trans.other-3.5]: "If
A and B are both lvalue reference types, COMMON-REF(A, B) is COND-RES(COPYCV(X,
Y) &, COPYCV( Y, X) &) if that type exists and is a reference type."
libstdc++ does not check that COMMON-REF(A, B) must be a reference type, which
will lead to incorrect determination of the common reference type according to
bullet 1 in the following cases.
https://godbolt.org/z/7Mc7jjesK
#include <concepts>
struct A {};
struct B { B(A); };
static_assert(
std::same_as<
std::common_reference_t<A&, B&&>, B>);