[Bug c++/41426] New: User defined conversion on return ignores array types
roger dot ferrer at bsc dot es
gcc-bugzilla@gcc.gnu.org
Mon Sep 21 12:51:00 GMT 2009
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
More information about the Gcc-bugs
mailing list