public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/17453] New: G++ type conversion bug
@ 2004-09-13 11:08 froloff at os2 dot ru
2004-09-13 11:34 ` [Bug c++/17453] " caj at cs dot york dot ac dot uk
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: froloff at os2 dot ru @ 2004-09-13 11:08 UTC (permalink / raw)
To: gcc-bugs
The folowing source produce an error in line 10 during compilation
=====================================================================
test.c: In function `void chk_gcc_bug()':
test.c:7: error: cannot convert `std::vector<_Tp, _Alloc>::begin() [with _Tp =
unsigned char, _Alloc = std::allocator<unsigned char>]()' from type `
__gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char,
std::allocator<unsigned char> > >' to type `unsigned char*'
====>8====================================>8=========================
#include <vector>
typedef std::vector<unsigned char> byte_vector;
void chk_gcc_bug()
{
byte_vector v(96 / 8);
unsigned char *ptr;
ptr= (unsigned char *)v.begin();
ptr= &(*(v.begin()));
}
====>8====================================>8=========================
Also check with gcc3.3.3 with the same result
Compiled fine with MSC v7.0
--
Summary: G++ type conversion bug
Product: gcc
Version: 3.2.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: froloff at os2 dot ru
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17453
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/17453] G++ type conversion bug
2004-09-13 11:08 [Bug c++/17453] New: G++ type conversion bug froloff at os2 dot ru
@ 2004-09-13 11:34 ` caj at cs dot york dot ac dot uk
2004-09-13 11:35 ` giovannibajo at libero dot it
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: caj at cs dot york dot ac dot uk @ 2004-09-13 11:34 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From caj at cs dot york dot ac dot uk 2004-09-13 11:34 -------
There is no reason why you should be able to cast an iterator to a pointer. msc
v7.0 must use a "pure pointer" as iterators while g++ doesn't. This isn't a bug.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17453
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/17453] G++ type conversion bug
2004-09-13 11:08 [Bug c++/17453] New: G++ type conversion bug froloff at os2 dot ru
2004-09-13 11:34 ` [Bug c++/17453] " caj at cs dot york dot ac dot uk
@ 2004-09-13 11:35 ` giovannibajo at libero dot it
2004-09-13 12:16 ` froloff at os2 dot ru
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: giovannibajo at libero dot it @ 2004-09-13 11:35 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From giovannibajo at libero dot it 2004-09-13 11:35 -------
Yes, and g++ has also a very good reason for not doing it: in debug mode, we
detect uses of invalid iterators and stuff, and raw pointers could not do that.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17453
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/17453] G++ type conversion bug
2004-09-13 11:08 [Bug c++/17453] New: G++ type conversion bug froloff at os2 dot ru
2004-09-13 11:34 ` [Bug c++/17453] " caj at cs dot york dot ac dot uk
2004-09-13 11:35 ` giovannibajo at libero dot it
@ 2004-09-13 12:16 ` froloff at os2 dot ru
2004-09-13 13:24 ` [Bug libstdc++/17453] " bangerth at dealii dot org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: froloff at os2 dot ru @ 2004-09-13 12:16 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From froloff at os2 dot ru 2004-09-13 12:15 -------
(In reply to comment #1)
> There is no reason why you should be able to cast an iterator to a pointer. msc
> v7.0 must use a "pure pointer" as iterators while g++ doesn't. This isn't a bug.
I didn't wait that it convert iterator to pointer by simple assignment, co I add
cast manually, and didn't saw any reaon why G++ can cast it.
So How I can read a number of vector elements? Or You propose to read it into
temp array of chars and the make assignment manually?
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17453
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/17453] G++ type conversion bug
2004-09-13 11:08 [Bug c++/17453] New: G++ type conversion bug froloff at os2 dot ru
` (2 preceding siblings ...)
2004-09-13 12:16 ` froloff at os2 dot ru
@ 2004-09-13 13:24 ` bangerth at dealii dot org
2004-09-13 13:47 ` giovannibajo at libero dot it
2004-09-14 6:42 ` froloff at os2 dot ru
5 siblings, 0 replies; 7+ messages in thread
From: bangerth at dealii dot org @ 2004-09-13 13:24 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-09-13 13:24 -------
Gcc doesn't do the conversion because the standard doesn't specifically
say it has to be able to. Our implementation uses some optimizations
that don't allow this simple conversion, because our iterations aren't
just pointers.
The solution to your problem is to either do an element-wise copy, or
if you are adventurous, use
&*vec.begin();
to get the address of the first element.
W.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Component|c++ |libstdc++
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17453
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/17453] G++ type conversion bug
2004-09-13 11:08 [Bug c++/17453] New: G++ type conversion bug froloff at os2 dot ru
` (3 preceding siblings ...)
2004-09-13 13:24 ` [Bug libstdc++/17453] " bangerth at dealii dot org
@ 2004-09-13 13:47 ` giovannibajo at libero dot it
2004-09-14 6:42 ` froloff at os2 dot ru
5 siblings, 0 replies; 7+ messages in thread
From: giovannibajo at libero dot it @ 2004-09-13 13:47 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From giovannibajo at libero dot it 2004-09-13 13:47 -------
> So How I can read a number of vector elements? Or You propose to read it into
> temp array of chars and the make assignment manually?
&v[0] is always an unsigned char* pointing to contiguous memory. But this is
not a question for GCC Bugzilla. I suggest you to buy some good STL book, or
ask similar questions in comp.lang.c++.moderated.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17453
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/17453] G++ type conversion bug
2004-09-13 11:08 [Bug c++/17453] New: G++ type conversion bug froloff at os2 dot ru
` (4 preceding siblings ...)
2004-09-13 13:47 ` giovannibajo at libero dot it
@ 2004-09-14 6:42 ` froloff at os2 dot ru
5 siblings, 0 replies; 7+ messages in thread
From: froloff at os2 dot ru @ 2004-09-14 6:42 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From froloff at os2 dot ru 2004-09-14 06:42 -------
Thanks to all for Your replays.
Best regards
Dmitry
PS
> &v[0] is always an unsigned char* pointing to contiguous memory.
I know about that, as You can see from attached source (line 11) ;)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17453
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2004-09-14 6:42 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-13 11:08 [Bug c++/17453] New: G++ type conversion bug froloff at os2 dot ru
2004-09-13 11:34 ` [Bug c++/17453] " caj at cs dot york dot ac dot uk
2004-09-13 11:35 ` giovannibajo at libero dot it
2004-09-13 12:16 ` froloff at os2 dot ru
2004-09-13 13:24 ` [Bug libstdc++/17453] " bangerth at dealii dot org
2004-09-13 13:47 ` giovannibajo at libero dot it
2004-09-14 6:42 ` froloff at os2 dot ru
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).