public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/46497] New: [C++0x] Defaulted vs declared move constructor vs is_convertible
@ 2010-11-16 10:54 paolo.carlini at oracle dot com
2010-11-16 11:06 ` [Bug c++/46497] " paolo.carlini at oracle dot com
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2010-11-16 10:54 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46497
Summary: [C++0x] Defaulted vs declared move constructor vs
is_convertible
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: paolo.carlini@oracle.com
I'm seeing the strange behavior summarized below, which prevents me from
implementing as-is the bit of N3140 about the defaulted move constructor.
////////////////////
#include <type_traits>
template<class _T1>
struct pair
{
_T1 first;
pair(const pair&) = default;
pair(pair&&) = default; // The static_assert triggers.
// pair(pair&&); // Works!
template<class _U1>
pair(pair<_U1>&&) { }
};
struct move_only
{
move_only(move_only&&) = default;
};
template<typename _Key>
class map
{
static_assert(std::is_convertible<pair<_Key>,
pair<const _Key>>::value, "");
};
map<move_only> m;
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/46497] [C++0x] Defaulted vs declared move constructor vs is_convertible
2010-11-16 10:54 [Bug c++/46497] New: [C++0x] Defaulted vs declared move constructor vs is_convertible paolo.carlini at oracle dot com
@ 2010-11-16 11:06 ` paolo.carlini at oracle dot com
2010-11-16 15:37 ` jason at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2010-11-16 11:06 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46497
--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2010-11-16 10:56:07 UTC ---
And for the record what I'm doing for the time being in the actual std::pair
is:
// XXX FIXME: should be defaulted per N3140. See c++/46497.
pair(pair&& __p)
: first(std::forward<first_type>(__p.first)),
second(std::forward<second_type>(__p.second)) { }
which works fine together with the rest of the C++0x features.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/46497] [C++0x] Defaulted vs declared move constructor vs is_convertible
2010-11-16 10:54 [Bug c++/46497] New: [C++0x] Defaulted vs declared move constructor vs is_convertible paolo.carlini at oracle dot com
2010-11-16 11:06 ` [Bug c++/46497] " paolo.carlini at oracle dot com
@ 2010-11-16 15:37 ` jason at gcc dot gnu.org
2010-11-17 1:44 ` jason at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2010-11-16 15:37 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46497
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2010.11.16 15:13:01
Ever Confirmed|0 |1
--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> 2010-11-16 15:13:01 UTC ---
Reduced:
template<class T>
struct A
{
T first;
A(const A&) = default;
A(A&&) = default;
template<class _U1>
A(A<_U1>&&);
};
struct move_only
{
move_only(move_only&&) = default;
};
A<move_only>&& f();
void g(A<const move_only>);
template<typename T>
static decltype(g(f())) h();
int main()
{
g(f());
h<int>();
}
There seems to be a problem with non-dependent types in templates; the plain
call to g(f()) works fine, but the call in the decltype fails.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/46497] [C++0x] Defaulted vs declared move constructor vs is_convertible
2010-11-16 10:54 [Bug c++/46497] New: [C++0x] Defaulted vs declared move constructor vs is_convertible paolo.carlini at oracle dot com
2010-11-16 11:06 ` [Bug c++/46497] " paolo.carlini at oracle dot com
2010-11-16 15:37 ` jason at gcc dot gnu.org
@ 2010-11-17 1:44 ` jason at gcc dot gnu.org
2010-11-17 2:04 ` paolo.carlini at oracle dot com
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2010-11-17 1:44 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46497
--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> 2010-11-17 01:43:13 UTC ---
Author: jason
Date: Wed Nov 17 01:43:10 2010
New Revision: 166851
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=166851
Log:
PR c++/46497
* call.c (build_over_call): Check for =delete even when trivial.
Added:
trunk/gcc/testsuite/g++.dg/cpp0x/defaulted20.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/call.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/46497] [C++0x] Defaulted vs declared move constructor vs is_convertible
2010-11-16 10:54 [Bug c++/46497] New: [C++0x] Defaulted vs declared move constructor vs is_convertible paolo.carlini at oracle dot com
` (2 preceding siblings ...)
2010-11-17 1:44 ` jason at gcc dot gnu.org
@ 2010-11-17 2:04 ` paolo.carlini at oracle dot com
2010-11-17 15:29 ` [Bug c++/46497] [C++0x] [4.6 Regression] " paolo.carlini at oracle dot com
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2010-11-17 2:04 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46497
--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> 2010-11-17 02:02:25 UTC ---
Jason, I'm sorry, I don't understand what's going on here: apparently nothing
changed for my original testcase: the assert still triggers, and it doesn't for
the non-defaulted variant?!?
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/46497] [C++0x] [4.6 Regression] Defaulted vs declared move constructor vs is_convertible
2010-11-16 10:54 [Bug c++/46497] New: [C++0x] Defaulted vs declared move constructor vs is_convertible paolo.carlini at oracle dot com
` (3 preceding siblings ...)
2010-11-17 2:04 ` paolo.carlini at oracle dot com
@ 2010-11-17 15:29 ` paolo.carlini at oracle dot com
2010-11-17 16:21 ` [Bug c++/46497] [C++0x] " jason at gcc dot gnu.org
2010-11-17 16:47 ` paolo.carlini at oracle dot com
6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2010-11-17 15:29 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46497
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[C++0x] Defaulted vs |[C++0x] [4.6 Regression]
|declared move constructor |Defaulted vs declared move
|vs is_convertible |constructor vs
| |is_convertible
--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2010-11-17 15:21:02 UTC ---
Barring evidence to the contrary, this is a regression: the testcase in Comment
#2 compiles with 4_5-branch.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/46497] [C++0x] Defaulted vs declared move constructor vs is_convertible
2010-11-16 10:54 [Bug c++/46497] New: [C++0x] Defaulted vs declared move constructor vs is_convertible paolo.carlini at oracle dot com
` (4 preceding siblings ...)
2010-11-17 15:29 ` [Bug c++/46497] [C++0x] [4.6 Regression] " paolo.carlini at oracle dot com
@ 2010-11-17 16:21 ` jason at gcc dot gnu.org
2010-11-17 16:47 ` paolo.carlini at oracle dot com
6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2010-11-17 16:21 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46497
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
Summary|[C++0x] [4.6 Regression] |[C++0x] Defaulted vs
|Defaulted vs declared move |declared move constructor
|constructor vs |vs is_convertible
|is_convertible |
--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> 2010-11-17 16:15:44 UTC ---
The difference between the user-written and =default versions is one of delayed
vs. immediate failure. With a defaulted constructor, at declaration time we
perform overload resolution and determine that we can't move 'first', so the
pair<const move_only> move constructor is deleted. We can't do that for a
user-written constructor, so we assume that it's OK, and give an error later
when we actually try to instantiate the move constructor.
So =default makes the ill-formedness available to SFINAE (pair<const move_only>
doesn't look move-constructible), whereas an explicitly written constructor
does not (it looks move-constructible but moving it causes an error).
In 4.5, move_only has an implicitly-declared copy constructor, so it is not a
move-only type. Explicitly deleting the copy constructor produces the expected
errors.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/46497] [C++0x] Defaulted vs declared move constructor vs is_convertible
2010-11-16 10:54 [Bug c++/46497] New: [C++0x] Defaulted vs declared move constructor vs is_convertible paolo.carlini at oracle dot com
` (5 preceding siblings ...)
2010-11-17 16:21 ` [Bug c++/46497] [C++0x] " jason at gcc dot gnu.org
@ 2010-11-17 16:47 ` paolo.carlini at oracle dot com
6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2010-11-17 16:47 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46497
--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> 2010-11-17 16:44:21 UTC ---
Ok, I'm still digesting all of this (and in the meanwhile we also realized that
likely we have problems in the specs of std::is_convertible itself, in the
library). Something still puzzling me is that, if I use the user-defined move
constructor, I *cannot* trigger errors, *ever*. Is it possible that we have an
accepts-invalid lurking somewhere?
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2010-11-17 16:44 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-16 10:54 [Bug c++/46497] New: [C++0x] Defaulted vs declared move constructor vs is_convertible paolo.carlini at oracle dot com
2010-11-16 11:06 ` [Bug c++/46497] " paolo.carlini at oracle dot com
2010-11-16 15:37 ` jason at gcc dot gnu.org
2010-11-17 1:44 ` jason at gcc dot gnu.org
2010-11-17 2:04 ` paolo.carlini at oracle dot com
2010-11-17 15:29 ` [Bug c++/46497] [C++0x] [4.6 Regression] " paolo.carlini at oracle dot com
2010-11-17 16:21 ` [Bug c++/46497] [C++0x] " jason at gcc dot gnu.org
2010-11-17 16:47 ` paolo.carlini at oracle dot com
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).