From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A8003385DC00; Sun, 5 Apr 2020 02:18:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A8003385DC00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1586053100; bh=TPpXV3K4RGOzLuVKL6AjbQgSVWusiZ1rwfaQYwcwc6g=; h=From:To:Subject:Date:From; b=A/9GbaJ2hJzztz/H8hkNtuZ6LVAtn3fSdMgMU6mTyhjUoq1tOUAHbbQvykF0VCtFn gvOzQk92LnaHirAQpZYHQWMWfA8+/Prihv8WaE1LX2erEV39O4xMEYvpK3wkLbtRLm Tc1BjRGT85jVa26Rz3wEkTayICHE6Q0NVbY7Zt58= From: "bisqwit at iki dot fi" To: gcc-bugs@gcc.gnu.org Subject: =?UTF-8?B?W0J1ZyBjKysvOTQ0OTBdIE5ldzogVGVybmFyeSBleHByZXNzaW9u?= =?UTF-8?B?IHdpdGggMyBjb25zdHMgaXMg4oCcbm904oCdIGEgY29uc3RhbnQgZXhwcmVz?= =?UTF-8?B?c2lvbg==?= Date: Sun, 05 Apr 2020 02:18:20 +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: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bisqwit at iki dot fi 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Apr 2020 02:18:20 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94490 Bug ID: 94490 Summary: Ternary expression with 3 consts is =E2=80=9Cnot=E2=80= =9D a constant expression Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: bisqwit at iki dot fi Target Milestone: --- Versions tested: GCC 9.3.0, GCC 10.0.1 20200324 (experimental) [master revi= sion 596c90d3559:023579257f5:906b3eb9df6c577d3f6e9c3ea5c9d7e4d1e90536] Error message: test6.cc: In instantiation of =E2=80=98auto Mul(const T&, const T2&) [with = T =3D std::array; T2 =3D std::array]=E2=80=99: test6.cc:20:58: required from here test6.cc:16:78: error: =E2=80=98(false ? std::tuple_size_v > : std::tuple_size_v >)=E2=80=99 is not a constant expres= sion 16 | return typename arith_result::type { std::get

(vec) ... }; |=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ^ test6.cc:20:6: error: =E2=80=98void x=E2=80=99 has incomplete type 20 | auto x =3D Mul(std::array{}, std::array{}); | ^ Compiler is erroneously claiming that an expression of type (x ? y : z) whe= re all of x,y,z are constant expressions, is not a constant expression. Code: #include #include template, std::size= _t B=3Dstd::tuple_size_v, std::size_t N =3D std::min(A,B), class S =3D std::make_index_sequence<(A> struct arith_result { using type =3D std::conditional_t(std::index_sequence) -> std::array..., std::tuple_element_t...>, N>{}(S{})), decltype([](std::index_sequence) -> std::tuple, std::tuple_element_t>...>{}(S{}))>; }; template, typename T2 =3D T> auto Mul(const T& vec, const T2& val) { return [&](std::index_sequence) { return typename arith_result::type { std::get

(vec) ..= . }; } (std::make_index_sequence<2>{}); } auto x =3D Mul(std::array{}, std::array{}); Note that if I replace the Mul function with this (inline the lambda call),= the problem goes away: template, typename T2 =3D T> auto Mul(const T& vec, const T2& val) { return typename arith_result::type { std::get<0>(vec),std::get<1>(vec) }; } Somehow the compiler forgets to do constant folding while it is processing = the lambda.=