public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/64385] odd behaviour of std::is_move_constructible< std::ostringstream >
       [not found] <bug-64385-4@http.gcc.gnu.org/bugzilla/>
@ 2014-12-27 20:27 ` redi at gcc dot gnu.org
  2014-12-27 20:56 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2014-12-27 20:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The problem is due to one of the bugs that PR 59002 depends on.

Prior to GCC 5 the stream classes have private copy constructors to make them
non-copyable. Normally (as you see when A is not defined) this means
is_move_constructible reports false, but when A is defined the first
instantiation of is_move_constructible<ostringstream> happens in a function
template, and G++ has a number of bugs in templates that mean access checking
doesn't work. This means the first instantiation occurs in a context where the
private copy constructor is (incorrectly) accessible, so it reports true. When
you use is_move_constructible again in main() it uses the existing
instantiation which gives the wrong result again.

The correct fix is to fix all the bugs linked to from PR 59002, but that's not
going to happen for GCC 4.9. An alternative would be to replace the private
constructors with deleted ones, so that the stream classes are not copyable
even in contexts where access checking doesn't work. I'm not sure that is worth
fixing now, given that the streams really are movable in GCC 5 anyway.


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

* [Bug c++/64385] odd behaviour of std::is_move_constructible< std::ostringstream >
       [not found] <bug-64385-4@http.gcc.gnu.org/bugzilla/>
  2014-12-27 20:27 ` [Bug c++/64385] odd behaviour of std::is_move_constructible< std::ostringstream > redi at gcc dot gnu.org
@ 2014-12-27 20:56 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2014-12-27 20:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
As a workaround you can simply instantiate the trait before it is used in the
function template.

Here's a reduced version of the test, which breaks when A is defined, but is
fixed by defining B:

#include <type_traits>
#include <ostream>

using trait = std::is_constructible<std::ostream, const std::ostream&>;

#if B
const bool dummy = trait::value;
#endif

#if A
template<bool> struct X { };

struct moveable_class
{
  template <typename Source>
  moveable_class(Source&& src, X<trait::value>* = 0)
  { }
};
#endif

static_assert( !trait::value, "");


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

end of thread, other threads:[~2014-12-27 20:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-64385-4@http.gcc.gnu.org/bugzilla/>
2014-12-27 20:27 ` [Bug c++/64385] odd behaviour of std::is_move_constructible< std::ostringstream > redi at gcc dot gnu.org
2014-12-27 20:56 ` 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).