public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/59768] New: [4.8 Regression] std::thread constructor not handling reference_wrapper correctly
@ 2014-01-11  7:34 Casey at Carter dot net
  2014-01-11 12:58 ` [Bug libstdc++/59768] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Casey at Carter dot net @ 2014-01-11  7:34 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 59768
           Summary: [4.8 Regression] std::thread constructor not handling
                    reference_wrapper correctly
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Casey at Carter dot net

Created attachment 31809
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31809&action=edit
Minimal test case.

Originally reported in Stackoverflow question
http://stackoverflow.com/questions/21059115/c11-thread-class-how-to-use-a-class-member-function

Construction of a std::thread with a pointer-to-member-function and
reference_wrapper as in this simple program:

#include <functional>
#include <iostream>
#include <thread>

class A {
public:
    void foo(int n) { std::cout << n << std::endl; }
};

int main()
{
    A a;

    std::thread t1(&A::foo, std::ref(a), 100);
    t1.join();
}

incorrectly results in a compilation error:

In file included from /usr/local/include/c++/4.8.2/thread:39:0,
                  from check.cc:2:
/usr/local/include/c++/4.8.2/functional: In instantiation of ‘struct
std::_Bind_simple<std::_Mem_fn<void (A::*)(int)>(std::reference_wrapper<A>,
int)>’:
/usr/local/include/c++/4.8.2/thread:137:47:   required from
‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void
(A::*)(int); _Args = {std::reference_wrapper<A>, int}]’
check.cc:13:42:   required from here
/usr/local/include/c++/4.8.2/functional:1697:61: error:no type named ‘type’ in
‘class std::result_of<std::_Mem_fn<void (A::*)(int)>(std::reference_wrapper<A>,
int)>’
        typedef typename result_of<_Callable(_Args...)>::type result_type;
                                                              ^
/usr/local/include/c++/4.8.2/functional:1727:9: error:no type named ‘type’ in
‘class std::result_of<std::_Mem_fn<void (A::*)(int)>(std::reference_wrapper<A>,
int)>’
          _M_invoke(_Index_tuple<_Indices...>)
          ^

I reduced the original program to:

#include <functional>
#include <thread>

int main() {
  struct A { void foo(int) {} } a;
  std::thread(&A::foo, std::ref(a), 100).join();
}

which still displays the erroneous behavior. Note that std::bind(&A::foo,
std::ref(a), 100) *does* compile correctly, as does a similar program in which
the member function foo has no parameter.

Program is incorrectly compiled by g++ 4.8.2 and 4.8.1, correctly compiles with
4.6.4 and 4.7.3.
>From gcc-bugs-return-440073-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sat Jan 11 08:14:47 2014
Return-Path: <gcc-bugs-return-440073-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 8928 invoked by alias); 11 Jan 2014 08:14:45 -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 8868 invoked by uid 48); 11 Jan 2014 08:14:41 -0000
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/28865] Structures with a flexible arrray member have wrong .size
Date: Sat, 11 Jan 2014 08:14:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: middle-end
X-Bugzilla-Version: 4.2.0
X-Bugzilla-Keywords: wrong-code
X-Bugzilla-Severity: normal
X-Bugzilla-Who: jakub at gcc dot gnu.org
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 4.7.4
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-28865-4-zc1Y3vUm39@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-28865-4@http.gcc.gnu.org/bugzilla/>
References: <bug-28865-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-01/txt/msg01215.txt.bz2
Content-length: 832

http://gcc.gnu.org/bugzilla/show_bug.cgi?id(865

--- Comment #18 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I disagree.  DECL_SIZE and .size are IMHO correct here at this point, and
component sizes (FIELD_DECL) can't match, because we shouldn't be changing the
type of the decl to some other type just because it got an initializer.  The
bug is IMHO really just in miscounting the size of the padding of the
initializer and thus emitting into the data/rodata etc. section more bytes of
data from what .size/arrays/-fsection-anchors assumes.  Outside of arrays on
non-fsection-anchors target this is just ugly (except where you e.g. put the
structs into named sections and use it as a kind of array say through
beginning/end of the named section), for -fsection-anchors it is of course a
wrong-code (well, wrong-data) bug.


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

end of thread, other threads:[~2014-01-11 19:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-11  7:34 [Bug libstdc++/59768] New: [4.8 Regression] std::thread constructor not handling reference_wrapper correctly Casey at Carter dot net
2014-01-11 12:58 ` [Bug libstdc++/59768] " redi at gcc dot gnu.org
2014-01-11 15:36 ` Casey at Carter dot net
2014-01-11 19:08 ` [Bug libstdc++/59768] [DR 2219] " redi 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).