[Bug c++/122007] New: inconsistent array decay to pointer in implicit conversion during function call
marco.foco at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Sep 19 22:48:56 GMT 2025
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122007
Bug ID: 122007
Summary: inconsistent array decay to pointer in implicit
conversion during function call
Product: gcc
Version: 13.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: marco.foco at gmail dot com
Target Milestone: ---
Created attachment 62420
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62420&action=edit
preprocessed file
I found an issue in pointer decay when temporary creation is involved.
I have a class with a constrained constructor, designed to accept pointers (but
reject arrays):
class A {
public:
template<typename T , std::enable_if_t<std::is_pointer_v<T>, bool> = true>
A(T&& p) {}
};
I added two functions to show the issue, one taking A by const& and one by
value
void f_ref(const A&) {}
void f_val(A) {}
The test code tries to create the object and call both functions using a
fixed-size array.
int main() {
const char v[4]{"abc"};
// A a{v}; // <- This is rejected (correct)
// f_ref(v); // <- this is rejected (correct)
f_val(v); // <- this is accepted (wrong)
}
The two commented lines are rejected, while the third one is accepted.
The compiler seems, only in that case, to decay the array into a pointer.
Adding a `=delete`d constructor with the inverse condition fixes the problem.
The code is available on godbolt here: https://godbolt.org/z/n68Wj38ej
I verified the issue on all GCC compiler version available on godbolt from 7.1
to 15.2, and on what godbolt reports as trunk.
MSVC and Clang reject all three lines.
Local test:
gcc version: 13.3.0
system: Ubuntu 24.04 x86_64 running on Windows WSL
command line: gcc-13 bug.cpp
compiler output: none (the code is accepted)
preprocessed file: attached
More information about the Gcc-bugs
mailing list