public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "roger dot ferrer at bsc dot es" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/41426]  New: User defined conversion on return ignores array types
Date: Mon, 21 Sep 2009 12:51:00 -0000	[thread overview]
Message-ID: <bug-41426-17480@http.gcc.gnu.org/bugzilla/> (raw)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1355 bytes --]

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	other threads:[~2009-09-21 12:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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-41426-17480@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: link
Be 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).