I think g++ simplifies too early array types into pointers when looking for a
conversion sequence in a return statement.

---
struct B
{
    B (int (&v)[10]);
    B();
};

B g2()
{
    int c[10];
    return c;
}
---

results in

test.cc: In function ‘B g2()’:
test.cc:10: error: conversion from ‘int*’ to non-scalar type ‘B’ requested

while at least the conversion constructor B::B(int (&)[10]) should be given a
chance.

For another (slightly) more elaborated example

---
template <typename _T>
struct A
{
    template <int _N>
        A(_T (&V)[_N]);
    A();
};

A<float> g1()
{
    float f[] = {1.1f, 2.3f};
    return f;
}
---

which gives

prova.cc: In function ‘A<float> g1()’:
prova.cc:12: error: conversion from ‘float*’ to non-scalar type ‘A<float>’
requested

Again, at least the 'A<T>::A<_N>(T (&)[_N])' constructor should be given a
chance (which eventually should succeed).

Using an explicit-conversion can be used as workaround.


-- 
           Summary: User defined conversion on return ignores array types
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: roger dot ferrer at bsc dot es


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41426

Reply via email to