public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kariya_mitsuru at hotmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/63604] New: [C++11] A direct-initialization of a reference should use explicit conversion functions
Date: Mon, 20 Oct 2014 18:48:00 -0000	[thread overview]
Message-ID: <bug-63604-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63604

            Bug ID: 63604
           Summary: [C++11] A direct-initialization of a reference should
                    use explicit conversion functions
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kariya_mitsuru at hotmail dot com

The sample code below should be compiled successfully but it causes compilation
error by gcc.

==========================================
struct T {};

struct S {
    explicit operator T() { return T(); }
};

int main()
{
    S s;
    T&& t(s);
    (void) t;
}
==========================================
cf. http://melpon.org/wandbox/permlink/LHgajpAXzqTbpYDc

An initialization of a reference in a direct-initialization context should use
an explicit conversion function that converts to a class prvalue.


The latest C++ standard (n4140) 13.3.1.6 [over.match.ref]/p.1.1 says that

The conversion functions of S and its base classes are considered.  Those
non-explicit conversion functions that are not hidden within S and yield type
“lvalue reference to cv2 T2” (when initializing an lvalue reference or an
rvalue reference to function) or “cv2 T2” or “rvalue reference to cv2 T2” (when
initializing an rvalue reference or an lvalue reference to function), where
“cv1 T” is reference-compatible (8.5.3) with “cv2 T2”, are candidate functions.
 For direct-initialization, those explicit conversion functions that are not
hidden within S and yield type “lvalue reference to cv2 T2” or “cv2 T2” or
“rvalue reference to cv2 T2”, respectively, where T2 is same type as T or can
be converted to type T with a qualification conversion (4.4), are also
candidate functions.


I think that this sample code corresponds to the case “For
direct-initialization, ...”.


Note that this sample code is compiled successfully if the conversion function
returns an rvalue reference.
(cf. http://melpon.org/wandbox/permlink/kGpALX7zvzHzi7K5)

See also BUG 48453.
>From gcc-bugs-return-464540-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Oct 20 18:48:05 2014
Return-Path: <gcc-bugs-return-464540-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 15531 invoked by alias); 20 Oct 2014 18:48:05 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 15405 invoked by uid 48); 20 Oct 2014 18:48:01 -0000
From: "su at cs dot ucdavis.edu" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/63605] New: wrong code at -O3 on x86_64-linux-gnu
Date: Mon, 20 Oct 2014 20:02:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: new
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: tree-optimization
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: su at cs dot ucdavis.edu
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter
Message-ID: <bug-63605-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-10/txt/msg01561.txt.bz2
Content-length: 1454

https://gcc.gnu.org/bugzilla/show_bug.cgi?idc605

            Bug ID: 63605
           Summary: wrong code at -O3 on x86_64-linux-gnu
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: su at cs dot ucdavis.edu

The current gcc trunk (as well as 4.8.x and 4.9.x) miscompiles the following
code on x86_64-linux at -O3 in both 32-bit and 64-bit modes.

This is a regression from 4.7.x.

The miscompilation seems to be caused by the tree vectorizer as
-fno-tree-vectorize makes it disappear.

$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-trunk/configure --prefix=/usr/local/gcc-trunk
--enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
gcc version 5.0.0 20141018 (experimental) [trunk revision 216429] (GCC)

$ gcc-trunk -O2 small.c; a.out
1
$ gcc-4.7 -O3 small.c; a.out
1
$
$ gcc-trunk -O3 small.c; a.out
0
$


--------------------------------


int printf (const char *, ...);

int a, b[8] = { 2, 0, 0, 0, 0, 0, 0, 0 }, c[8];

int
main ()
{
  int d;
  for (; a < 8; a++)
    {
      d = b[a] >> 1;
      c[a] = d != 0;
    }
  printf ("%d\n", c[0]);
  return 0;
}


             reply	other threads:[~2014-10-20 18:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-20 18:48 kariya_mitsuru at hotmail dot com [this message]
2014-12-12 15:14 ` [Bug c++/63604] " ville.voutilainen at gmail dot com
2014-12-13 18:19 ` ville.voutilainen at gmail dot com
2021-09-06  8:53 ` pinskia at gcc dot gnu.org
2021-09-06  8:53 ` pinskia at gcc dot gnu.org
2021-09-06  8:58 ` pinskia at gcc dot gnu.org

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-63604-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: 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).