From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6D2E53858435; Mon, 22 Apr 2024 19:53:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D2E53858435 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1713815596; bh=kNfGcITGY4I6kftecQj7t0wECC04mf3Q35r/97AyWSM=; h=From:To:Subject:Date:From; b=VoG4pktSAYIw4/4bg6Tl/deMhAhKtisiQUbeDQ7E62ATxso0UIggyPp0CXtow1EXD GBFWwaC3MyO6trQws3GzN7h1t/9Hmva/ku3DCx7I25EtO0D/pWZqui8I/vs3ENsT6e cZ6b7eTWMCFY7y5G7dNM7Q+r3lYhsS+HcfweFaug= From: "rkraesig at mozilla dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/114812] New: Arguments of array type decay to pointer type too eagerly when used as arguments to ref- or ptr-to-function Date: Mon, 22 Apr 2024 19:53:15 +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.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rkraesig at mozilla 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=3D114812 Bug ID: 114812 Summary: Arguments of array type decay to pointer type too eagerly when used as arguments to ref- or ptr-to-function Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: rkraesig at mozilla dot com Target Milestone: --- In a function-call expression, if the value F invoked as a function is of t= ype reference-to-function or pointer-to-function, a value of reference-to-array type passed as an argument to F appears to be immediately converted to the corresponding pointer type to which it would decay. This prevents implicit converting constructors for the nominal argument typ= es of F which would convert from reference-to-array from being found. This does not occur if F is of function type, nor if it is of some object t= ype with an `operator()`; in these cases the array type is passed without decay. Example code (also at https://godbolt.org/z/jjKE31G7r): struct S { S(const int (&)[2]) {} // S(const int *) {} // footnote [0] }; static const int arr[] =3D {17, 42}; void func(S s) {} void test() { void (&f)(S) =3D func; f(arr); // fails on GCC; succeeds on clang & MSVC // func(arr); // succeeds everywhere // (std::function{f})(arr); // succeeds everywhere } [0] If this alternate constructor is uncommented, the above code will compi= le successfully under GCC... but will fail to compile on clang and MSVC, which reject `f(arr);` as ambiguous. Per testing on godbolt, this is not a recent regression, but appears to hap= pen on every version of GCC back to at least 4.1.2.=