From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BD4A438582B4; Sun, 30 Oct 2022 08:17:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD4A438582B4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667117875; bh=thhIVDqtOXXZatNZYOIHAvxJpb86yfykQXvYCx7Jbp4=; h=From:To:Subject:Date:From; b=YLRTBvDU0HqwNSAbVEI8smOEmOvBfYMqsi3+tOIEBMjqKkWeQ7fv2kBOzKjFAS/kQ yxQ1b8au566eUzA2Jy8kitCnOmQmdtYlxXIe8TwAsyqE7dDZtE5Kl+cUbeqV+JUS4q OKRdVqWvR3arRQXpSiK8j68OWsC9mdlvbf858khs= From: "jlame646 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107461] New: GCC rejects program with ambiguity error Date: Sun, 30 Oct 2022 08:17:51 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jlame646 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107461 Bug ID: 107461 Summary: GCC rejects program with ambiguity error Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jlame646 at gmail dot com Target Milestone: --- The following well-formed program(afaik) is rejected by gcc but accepted by clang and msbc. Demo: https://godbolt.org/z/bMWxd8bEa ``` #include #include #include #include #include #include #include using namespace std; #include #include #include #include namespace MLL{ template class Matrix; //this forward declaration not needed but you can have this if you want and if you do then make sure that you only provide the def= ault arg 256 in declaration and not in definition //-------------------------------------------------------------------------= -------vvvvvvv---->added this default arg here instead of in forward declaration template class Matrix{ static constexpr bool IS_STATIC =3D n_rows * n_cols <=3D MAX; using container_t =3D typename std::conditional, std::vector>::type; container_t m_data_list; public: Matrix(){ if constexpr( !IS_STATIC ){ m_data_list.resize(n_rows * n_cols); } } explicit Matrix(data_t default_value){ if constexpr( IS_STATIC ){ m_data_list.fill(default_value); }else{ m_data_list.resize(n_rows * n_cols, default_value); } } explicit Matrix(std::initializer_list&& value_list){ std::copy(value_list.begin(), value_list.end(), m_data_list.begin()); } Matrix(Matrix const& other) : m_data_list(other.m_data_list){ } Matrix(Matrix&& other) noexcept : m_data_list(std::move(other.m_data_list)){ } Matrix& operator=3D(Matrix const& other){ m_data_list =3D other.m_data_list; return *this; } Matrix& operator=3D(Matrix&& other) noexcept{ m_data_list =3D std::move(other.m_data_list); return *this; } //renamed all the arguments by prefexing them with OP for better readibility template friend Matrix() + std::declval()), n_rowst, n_colsOP, std::min(MAXOP, other_MAXOP)> operator+(Matrix const& lhs, Matrix const& rhs); }; template Matrix() + std::declval()), n_rows= t, n_colsOP, std::min(MAXOP, other_MAXOP)> operator+(Matrix const& lhs, Matrix const& rhs){ const std::size_t n =3D n_rowst * n_colsOP; for( std::size_t i =3D 0; i < n; ++i ){ // lhs.m_data_list[i] +=3D rhs.m_data_list[i]; //can't assing = using const lvalue reference } return lhs; } } int main() { MLL::Matrix a({1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}); a+a; return 0;; } ``` GCC rejects this with the error: ``` :82:6: error: ambiguous overload for 'operator+' (operand types are 'MLL::Matrix' and 'MLL::Matrix') 82 | a+a; | ~^~ | | | | | Matrix<[...],[...],[...]> | Matrix<[...],[...],[...]> :70:5: note: candidate: 'MLL::Matrix()= + declval())), n_rowst, n_colsOP, std::min(MAXOP, other_MAXOP)> MLL::operator+(const Matrix&, const Matrix&) [with data_tOP =3D int;= TOP =3D int; long unsigned int n_rowst =3D 4; long unsigned int n_colsOP =3D 4; long unsigned int MAXOP =3D 256; long unsigned int other_MAXOP =3D 256; decltype ((declval() + declval())) =3D int]' 70 | operator+(Matrix const& lhs, Matrix const& rhs){ | ^~~~~~~~ :65:5: note: candidate: 'MLL::Matrix()= + declval())), n_rowst, n_colsOP, std::min(MAXOP, other_MAXOP)> MLL::operator+(const Matrix&, const Matrix&) [with data_tOP =3D int;= TOP =3D int; long unsigned int n_rowst =3D 4; long unsigned int n_colsOP =3D 4; long unsigned int MAXOP =3D 256; long unsigned int other_MAXOP =3D 256; data_t = =3D int; long unsigned int n_rows =3D 4; long unsigned int n_cols =3D 4; long unsign= ed int MAX =3D 256; decltype ((declval() + declval())) =3D int]' 65 | operator+(Matrix const& lhs, Matrix const& rhs); | ^~~~~~~~ ```=