public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/38265] New: STL treats explicit constructors as converting constructors
@ 2008-11-25 19:13 konto dot dydaktyczne at gmail dot com
2008-11-25 19:36 ` [Bug c++/38265] " cfairles at gcc dot gnu dot org
` (11 more replies)
0 siblings, 12 replies; 13+ messages in thread
From: konto dot dydaktyczne at gmail dot com @ 2008-11-25 19:13 UTC (permalink / raw)
To: gcc-bugs
When some STL containers are created, explicit constructors for contained
objects are treated as converting constructors. The keyword "explicit" is
ignored, and no error message is issued; see the code.
#include <vector>
#include <deque>
class X {
public:
explicit X(int) {}
};
int main() {
int a[1] = {};
std::vector<X> v(a, a + 1);
std::deque<X> d(a, a + 1);
}
--
Summary: STL treats explicit constructors as converting
constructors
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: konto dot dydaktyczne at gmail dot com
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38265
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/38265] STL treats explicit constructors as converting constructors
2008-11-25 19:13 [Bug c++/38265] New: STL treats explicit constructors as converting constructors konto dot dydaktyczne at gmail dot com
@ 2008-11-25 19:36 ` cfairles at gcc dot gnu dot org
2008-11-25 19:49 ` [Bug libstdc++/38265] " paolo dot carlini at oracle dot com
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: cfairles at gcc dot gnu dot org @ 2008-11-25 19:36 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from cfairles at gcc dot gnu dot org 2008-11-25 19:34 -------
GCC 4.4.0 also accepts this code as does Comeau 4.3.10.1.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38265
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/38265] STL treats explicit constructors as converting constructors
2008-11-25 19:13 [Bug c++/38265] New: STL treats explicit constructors as converting constructors konto dot dydaktyczne at gmail dot com
2008-11-25 19:36 ` [Bug c++/38265] " cfairles at gcc dot gnu dot org
@ 2008-11-25 19:49 ` paolo dot carlini at oracle dot com
2008-11-28 10:08 ` konto dot dydaktyczne at gmail dot com
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: paolo dot carlini at oracle dot com @ 2008-11-25 19:49 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from paolo dot carlini at oracle dot com 2008-11-25 19:48 -------
Unless I'm badly mistaken, this behaviour, dating back to the original HP/SGI
STL and as such very difficult to change now, is a small extension due to the
use in the containers of _Construct instead of calling allocator::construct
directly. All in all, at the moment I don't think we have good reasons to
change it.
--
paolo dot carlini at oracle dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|c++ |libstdc++
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38265
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/38265] STL treats explicit constructors as converting constructors
2008-11-25 19:13 [Bug c++/38265] New: STL treats explicit constructors as converting constructors konto dot dydaktyczne at gmail dot com
2008-11-25 19:36 ` [Bug c++/38265] " cfairles at gcc dot gnu dot org
2008-11-25 19:49 ` [Bug libstdc++/38265] " paolo dot carlini at oracle dot com
@ 2008-11-28 10:08 ` konto dot dydaktyczne at gmail dot com
2008-11-28 10:52 ` paolo dot carlini at oracle dot com
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: konto dot dydaktyczne at gmail dot com @ 2008-11-28 10:08 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from konto dot dydaktyczne at gmail dot com 2008-11-28 10:07 -------
Let me add an std::list and an std::set to my code; see below. Both additions
produce errors. So,
[sequence containers]
std::vector -> no error signaled, "explicit" ignored
std::list -> error signaled, because of "explicit"
std::deque -> no error signaled, "explicit" ignored
[associative containers]
std::set -> error signaled, because of "explicit"
#include <vector>
#include <deque>
#include <list>
#include <set>
class X {
public:
explicit X(int) {}
int operator<(const X&) const {
return 0;
}
};
int main() {
int a[1] = {};
std::vector<X> v(a, a + 1);
std::deque<X> d(a, a + 1);
std::list<X> l(a, a + 1);
std::set<X> s(a, a + 1);
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38265
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/38265] STL treats explicit constructors as converting constructors
2008-11-25 19:13 [Bug c++/38265] New: STL treats explicit constructors as converting constructors konto dot dydaktyczne at gmail dot com
` (2 preceding siblings ...)
2008-11-28 10:08 ` konto dot dydaktyczne at gmail dot com
@ 2008-11-28 10:52 ` paolo dot carlini at oracle dot com
2008-11-28 11:05 ` paolo dot carlini at oracle dot com
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: paolo dot carlini at oracle dot com @ 2008-11-28 10:52 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from paolo dot carlini at oracle dot com 2008-11-28 10:50 -------
Yes, this is obvious, just grep for _Construct.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38265
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/38265] STL treats explicit constructors as converting constructors
2008-11-25 19:13 [Bug c++/38265] New: STL treats explicit constructors as converting constructors konto dot dydaktyczne at gmail dot com
` (3 preceding siblings ...)
2008-11-28 10:52 ` paolo dot carlini at oracle dot com
@ 2008-11-28 11:05 ` paolo dot carlini at oracle dot com
2008-11-28 11:18 ` paolo dot carlini at oracle dot com
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: paolo dot carlini at oracle dot com @ 2008-11-28 11:05 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from paolo dot carlini at oracle dot com 2008-11-28 11:03 -------
But I see now that al long time ago list & co also used _Construct, this is
indeed an inconsistency... Let's see what we can do here...
--
paolo dot carlini at oracle dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |paolo dot carlini at oracle
|dot org |dot com
Status|UNCONFIRMED |ASSIGNED
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2008-11-28 11:03:38
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38265
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/38265] STL treats explicit constructors as converting constructors
2008-11-25 19:13 [Bug c++/38265] New: STL treats explicit constructors as converting constructors konto dot dydaktyczne at gmail dot com
` (4 preceding siblings ...)
2008-11-28 11:05 ` paolo dot carlini at oracle dot com
@ 2008-11-28 11:18 ` paolo dot carlini at oracle dot com
2008-11-28 11:24 ` konto dot dydaktyczne at gmail dot com
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: paolo dot carlini at oracle dot com @ 2008-11-28 11:18 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from paolo dot carlini at oracle dot com 2008-11-28 11:17 -------
Hummm, the issue seems different than I remembered it. Will see..
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38265
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/38265] STL treats explicit constructors as converting constructors
2008-11-25 19:13 [Bug c++/38265] New: STL treats explicit constructors as converting constructors konto dot dydaktyczne at gmail dot com
` (5 preceding siblings ...)
2008-11-28 11:18 ` paolo dot carlini at oracle dot com
@ 2008-11-28 11:24 ` konto dot dydaktyczne at gmail dot com
2008-11-28 11:31 ` paolo dot carlini at oracle dot com
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: konto dot dydaktyczne at gmail dot com @ 2008-11-28 11:24 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from konto dot dydaktyczne at gmail dot com 2008-11-28 11:23 -------
(In reply to comment #1)
> GCC 4.4.0 also accepts this code as does Comeau 4.3.10.1.
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
does not accept this code.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38265
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/38265] STL treats explicit constructors as converting constructors
2008-11-25 19:13 [Bug c++/38265] New: STL treats explicit constructors as converting constructors konto dot dydaktyczne at gmail dot com
` (6 preceding siblings ...)
2008-11-28 11:24 ` konto dot dydaktyczne at gmail dot com
@ 2008-11-28 11:31 ` paolo dot carlini at oracle dot com
2008-11-28 11:41 ` paolo dot carlini at oracle dot com
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: paolo dot carlini at oracle dot com @ 2008-11-28 11:31 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from paolo dot carlini at oracle dot com 2008-11-28 11:30 -------
The issue is different because if I remove all uses of _Construct and implement
the various uninitialized_* per the letter of the Standard, nothing changes...
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38265
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/38265] STL treats explicit constructors as converting constructors
2008-11-25 19:13 [Bug c++/38265] New: STL treats explicit constructors as converting constructors konto dot dydaktyczne at gmail dot com
` (7 preceding siblings ...)
2008-11-28 11:31 ` paolo dot carlini at oracle dot com
@ 2008-11-28 11:41 ` paolo dot carlini at oracle dot com
2008-11-29 16:37 ` konto dot dydaktyczne at gmail dot com
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: paolo dot carlini at oracle dot com @ 2008-11-28 11:41 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from paolo dot carlini at oracle dot com 2008-11-28 11:40 -------
... and I'm coming to the conclusion that this is not a bug in our library.
Consider the std::vector case: I cannot see anything wrong with using
std::uninitialized_copy in the implementation of the constructor. In turn, the
former does, per the Standard:
::new(static_cast<void*>(&*__cur)) typename
iterator_traits<_ForwardIterator>::value_type(*__first);
thus, the explicit constructor can be used.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38265
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/38265] STL treats explicit constructors as converting constructors
2008-11-25 19:13 [Bug c++/38265] New: STL treats explicit constructors as converting constructors konto dot dydaktyczne at gmail dot com
` (8 preceding siblings ...)
2008-11-28 11:41 ` paolo dot carlini at oracle dot com
@ 2008-11-29 16:37 ` konto dot dydaktyczne at gmail dot com
2008-11-29 16:42 ` konto dot dydaktyczne at gmail dot com
2008-11-29 17:07 ` paolo dot carlini at oracle dot com
11 siblings, 0 replies; 13+ messages in thread
From: konto dot dydaktyczne at gmail dot com @ 2008-11-29 16:37 UTC (permalink / raw)
To: gcc-bugs
------- Comment #10 from konto dot dydaktyczne at gmail dot com 2008-11-29 16:36 -------
(In reply to comment #9)
The Standard does not require that std::uninitialized_copy be invoked when
constructing an std::vector or std::deque.
Moreover, an explicit constructor constructs objects only where the
direct-initialization syntax or where casts are explicitly used. None of these
cases occurs in the code above.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38265
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/38265] STL treats explicit constructors as converting constructors
2008-11-25 19:13 [Bug c++/38265] New: STL treats explicit constructors as converting constructors konto dot dydaktyczne at gmail dot com
` (9 preceding siblings ...)
2008-11-29 16:37 ` konto dot dydaktyczne at gmail dot com
@ 2008-11-29 16:42 ` konto dot dydaktyczne at gmail dot com
2008-11-29 17:07 ` paolo dot carlini at oracle dot com
11 siblings, 0 replies; 13+ messages in thread
From: konto dot dydaktyczne at gmail dot com @ 2008-11-29 16:42 UTC (permalink / raw)
To: gcc-bugs
------- Comment #11 from konto dot dydaktyczne at gmail dot com 2008-11-29 16:40 -------
(In reply to comment #10)
> an explicit constructor constructs objects only where the
> direct-initialization syntax or where casts are explicitly used. None of these
> cases occurs in the code above.
I mean the code in the bug description.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38265
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug libstdc++/38265] STL treats explicit constructors as converting constructors
2008-11-25 19:13 [Bug c++/38265] New: STL treats explicit constructors as converting constructors konto dot dydaktyczne at gmail dot com
` (10 preceding siblings ...)
2008-11-29 16:42 ` konto dot dydaktyczne at gmail dot com
@ 2008-11-29 17:07 ` paolo dot carlini at oracle dot com
11 siblings, 0 replies; 13+ messages in thread
From: paolo dot carlini at oracle dot com @ 2008-11-29 17:07 UTC (permalink / raw)
To: gcc-bugs
------- Comment #12 from paolo dot carlini at oracle dot com 2008-11-29 17:05 -------
Subject: Re: STL treats explicit constructors as converting constructors
> The Standard does not require that std::uninitialized_copy be
> invoked when
> constructing an std::vector or...
Sure, but certainly doesn't forbid it, and I maintain is the natural
choice in this case.
>
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38265
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2008-11-29 17:07 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-25 19:13 [Bug c++/38265] New: STL treats explicit constructors as converting constructors konto dot dydaktyczne at gmail dot com
2008-11-25 19:36 ` [Bug c++/38265] " cfairles at gcc dot gnu dot org
2008-11-25 19:49 ` [Bug libstdc++/38265] " paolo dot carlini at oracle dot com
2008-11-28 10:08 ` konto dot dydaktyczne at gmail dot com
2008-11-28 10:52 ` paolo dot carlini at oracle dot com
2008-11-28 11:05 ` paolo dot carlini at oracle dot com
2008-11-28 11:18 ` paolo dot carlini at oracle dot com
2008-11-28 11:24 ` konto dot dydaktyczne at gmail dot com
2008-11-28 11:31 ` paolo dot carlini at oracle dot com
2008-11-28 11:41 ` paolo dot carlini at oracle dot com
2008-11-29 16:37 ` konto dot dydaktyczne at gmail dot com
2008-11-29 16:42 ` konto dot dydaktyczne at gmail dot com
2008-11-29 17:07 ` paolo dot 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).