public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "rkraesig at mozilla dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-114812-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114812 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 type 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 types 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 type 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[] = {17, 42}; void func(S s) {} void test() { void (&f)(S) = 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 compile 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 happen on every version of GCC back to at least 4.1.2.
next reply other threads:[~2024-04-22 19:53 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-04-22 19:53 rkraesig at mozilla dot com [this message] 2024-04-22 19:57 ` [Bug c++/114812] " pinskia at gcc dot gnu.org 2024-04-22 20:12 ` rkraesig at mozilla dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-114812-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).