public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66893] New: disallowed initialization of reference with user-defined conversion function
@ 2015-07-16  3:44 barry.revzin at gmail dot com
  2015-07-16 11:31 ` [Bug c++/66893] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: barry.revzin at gmail dot com @ 2015-07-16  3:44 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 66893
           Summary: disallowed initialization of reference with
                    user-defined conversion function
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

Consider the following:

struct B {};
struct S { explicit operator B(); };

int main() {
    B const &t(S{});
}

According to [over.match.ref]: 

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.

In this case, B const (cv1 T) is reference-compatible with B (cv2 T2), so the
operator should be a candidate function. However, gcc rejects it:

main.cpp: In function 'int main()':
main.cpp:5:19: error: invalid initialization of reference of type 'const B&'
from expression of type 'S'
     B const &t(S{});
                   ^
>From gcc-bugs-return-492394-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Jul 16 04:35:53 2015
Return-Path: <gcc-bugs-return-492394-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 46865 invoked by alias); 16 Jul 2015 04:35:53 -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 46829 invoked by uid 48); 16 Jul 2015 04:35:49 -0000
From: "bin.x.fan at oracle dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/66842] libatomic uses multiple locks for locked atomics
Date: Thu, 16 Jul 2015 04:35:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 4.9.2
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: bin.x.fan at oracle dot com
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Resolution:
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: component
Message-ID: <bug-66842-4-1Q0TP3oX2A@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-66842-4@http.gcc.gnu.org/bugzilla/>
References: <bug-66842-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: 2015-07/txt/msg01284.txt.bz2
Content-length: 1125

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

Bin Fan <bin.x.fan at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |c++

--- Comment #4 from Bin Fan <bin.x.fan at oracle dot com> ---
Since I don't see any response from C so far, I change the example to C++ code,
and change the category to c++. Could C++ folks take a look?

-bash-4.2$ cat c++11_locked_atomics.cpp
#include <atomic>
using namespace std;

#ifndef SIZE
#define SIZE 1024
#endif

typedef struct {
    char a[SIZE];
} lock_obj_t;

extern "C" {
extern void display_nlocks ();
}

int main()
{
    lock_obj_t v2 = {0};
    atomic<lock_obj_t> v1 = ATOMIC_VAR_INIT(v2);
    v2 = atomic_load (&v1);
    display_nlocks ();
    return 0;
}

gcc -shared -ldl -fPIC libmythread.c -o libmythread.so -g
g++ -std=c++11 -latomic c++11_locked_atomics.cpp -DSIZE 48 -g -L./
-Wl,-rpath=./ -lmythread
+ LD_PRELOAD=./libmythread.so
+ a.out
pthread_mutex_lock is called 32 times

The g++ version is still 4.9.2.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-06  8:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-16  3:44 [Bug c++/66893] New: disallowed initialization of reference with user-defined conversion function barry.revzin at gmail dot com
2015-07-16 11:31 ` [Bug c++/66893] " redi at gcc dot gnu.org
2015-07-16 12:25 ` [Bug c++/66893] disallowed initialization of reference with explicit " redi at gcc dot gnu.org
2021-09-06  8:53 ` pinskia at gcc dot gnu.org

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