public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/67503] New: String cannot be loaded from binary representation
@ 2015-09-08 16:28 radventure at yandex dot ru
  2015-09-08 16:32 ` [Bug libstdc++/67503] " redi at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: radventure at yandex dot ru @ 2015-09-08 16:28 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 67503
           Summary: String cannot be loaded from binary representation
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: radventure at yandex dot ru
  Target Milestone: ---

#include <iostream>
#include <string>

int main() {
  unsigned char buff1[sizeof(std::string)], buff2[sizeof(std::string)];
  std::string s1("SMAL STRING BUG"), s2;
  new (&buff1) std::string(s1);
  s2 = *(reinterpret_cast<std::string*>(&buff1));
  std::cout << s2 << std::endl;
  std::swap(buff1, buff2);
  s2 = *(reinterpret_cast<std::string*>(&buff2));
  std::cout << s2 << std::endl;
}

After swapping buffers _N_dataplus._M_p pointer points into we buff1 but actual
data stored in small local buffer was coped correctly. If initial string length
will be greater when data will be stored into the heap and everything will be
Ok.


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

* [Bug libstdc++/67503] String cannot be loaded from binary representation
  2015-09-08 16:28 [Bug libstdc++/67503] New: String cannot be loaded from binary representation radventure at yandex dot ru
@ 2015-09-08 16:32 ` redi at gcc dot gnu.org
  2015-09-08 16:40 ` pinskia at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2015-09-08 16:32 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
That's not valid, you can't do that with non-trivial types.


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

* [Bug libstdc++/67503] String cannot be loaded from binary representation
  2015-09-08 16:28 [Bug libstdc++/67503] New: String cannot be loaded from binary representation radventure at yandex dot ru
  2015-09-08 16:32 ` [Bug libstdc++/67503] " redi at gcc dot gnu.org
@ 2015-09-08 16:40 ` pinskia at gcc dot gnu.org
  2015-09-08 16:54 ` radventure at yandex dot ru
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2015-09-08 16:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Also there is an alignment issue with your example too.


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

* [Bug libstdc++/67503] String cannot be loaded from binary representation
  2015-09-08 16:28 [Bug libstdc++/67503] New: String cannot be loaded from binary representation radventure at yandex dot ru
  2015-09-08 16:32 ` [Bug libstdc++/67503] " redi at gcc dot gnu.org
  2015-09-08 16:40 ` pinskia at gcc dot gnu.org
@ 2015-09-08 16:54 ` radventure at yandex dot ru
  2015-09-08 16:56 ` radventure at yandex dot ru
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: radventure at yandex dot ru @ 2015-09-08 16:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from radventure at yandex dot ru ---
I can solve the alignment but prbolem will not be fixed. 
I agree with remark about "non-trivial types" but this code works in previous
gcc versions and works in visual c++ 2015.


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

* [Bug libstdc++/67503] String cannot be loaded from binary representation
  2015-09-08 16:28 [Bug libstdc++/67503] New: String cannot be loaded from binary representation radventure at yandex dot ru
                   ` (2 preceding siblings ...)
  2015-09-08 16:54 ` radventure at yandex dot ru
@ 2015-09-08 16:56 ` radventure at yandex dot ru
  2015-09-08 17:03 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: radventure at yandex dot ru @ 2015-09-08 16:56 UTC (permalink / raw)
  To: gcc-bugs

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

radventure at yandex dot ru changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |WONTFIX


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

* [Bug libstdc++/67503] String cannot be loaded from binary representation
  2015-09-08 16:28 [Bug libstdc++/67503] New: String cannot be loaded from binary representation radventure at yandex dot ru
                   ` (3 preceding siblings ...)
  2015-09-08 16:56 ` radventure at yandex dot ru
@ 2015-09-08 17:03 ` redi at gcc dot gnu.org
  2015-09-08 17:05 ` radventure at yandex dot ru
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2015-09-08 17:03 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|WONTFIX                     |INVALID

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to radventure from comment #3)
> I can solve the alignment but prbolem will not be fixed. 
> I agree with remark about "non-trivial types" but this code works in
> previous gcc versions and works in visual c++ 2015.

It was never valid before and it's not valid now. Just because it appeared to
work previously doesn't make it valid.


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

* [Bug libstdc++/67503] String cannot be loaded from binary representation
  2015-09-08 16:28 [Bug libstdc++/67503] New: String cannot be loaded from binary representation radventure at yandex dot ru
                   ` (4 preceding siblings ...)
  2015-09-08 17:03 ` redi at gcc dot gnu.org
@ 2015-09-08 17:05 ` radventure at yandex dot ru
  2015-09-08 17:08 ` radventure at yandex dot ru
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: radventure at yandex dot ru @ 2015-09-08 17:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from radventure at yandex dot ru ---
When you use local buffer for storing string value it not necessary to have
pointer to it. And we can reduce the size of string by the syzeof(pointer).


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

* [Bug libstdc++/67503] String cannot be loaded from binary representation
  2015-09-08 16:28 [Bug libstdc++/67503] New: String cannot be loaded from binary representation radventure at yandex dot ru
                   ` (5 preceding siblings ...)
  2015-09-08 17:05 ` radventure at yandex dot ru
@ 2015-09-08 17:08 ` radventure at yandex dot ru
  2015-09-08 17:09 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: radventure at yandex dot ru @ 2015-09-08 17:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from radventure at yandex dot ru ---
(In reply to Jonathan Wakely from comment #4)
> (In reply to radventure from comment #3)
> > I can solve the alignment but prbolem will not be fixed. 
> > I agree with remark about "non-trivial types" but this code works in
> > previous gcc versions and works in visual c++ 2015.
> 
> It was never valid before and it's not valid now. Just because it appeared
> to work previously doesn't make it valid.

Code validity it's great. But what about backward compatibility?


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

* [Bug libstdc++/67503] String cannot be loaded from binary representation
  2015-09-08 16:28 [Bug libstdc++/67503] New: String cannot be loaded from binary representation radventure at yandex dot ru
                   ` (6 preceding siblings ...)
  2015-09-08 17:08 ` radventure at yandex dot ru
@ 2015-09-08 17:09 ` pinskia at gcc dot gnu.org
  2015-09-08 17:12 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2015-09-08 17:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is just like having a struct like:
Struct
{
  Char a[4];
  Char *b = a;
};

Sorry for char and struct being in the wrong case. Also using a c++11 feature
to show the case easier.  This is a valid thing to do and that is exactly what
the new std::string does. This saves space and allows for short strings not
have to an extra allocation.


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

* [Bug libstdc++/67503] String cannot be loaded from binary representation
  2015-09-08 16:28 [Bug libstdc++/67503] New: String cannot be loaded from binary representation radventure at yandex dot ru
                   ` (7 preceding siblings ...)
  2015-09-08 17:09 ` pinskia at gcc dot gnu.org
@ 2015-09-08 17:12 ` pinskia at gcc dot gnu.org
  2015-09-08 17:15 ` radventure at yandex dot ru
  2015-09-08 17:25 ` radventure at yandex dot ru
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2015-09-08 17:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to radventure from comment #5)
> When you use local buffer for storing string value it not necessary to have
> pointer to it. And we can reduce the size of string by the syzeof(pointer).

Well an union would work here except it would make all other code more messy.
There are a few places need to check that it equals the array before doing
something special.


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

* [Bug libstdc++/67503] String cannot be loaded from binary representation
  2015-09-08 16:28 [Bug libstdc++/67503] New: String cannot be loaded from binary representation radventure at yandex dot ru
                   ` (8 preceding siblings ...)
  2015-09-08 17:12 ` pinskia at gcc dot gnu.org
@ 2015-09-08 17:15 ` radventure at yandex dot ru
  2015-09-08 17:25 ` radventure at yandex dot ru
  10 siblings, 0 replies; 12+ messages in thread
From: radventure at yandex dot ru @ 2015-09-08 17:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from radventure at yandex dot ru ---
I understand the "small string optimization" idea. I agree about allocation
counting. But I don't see space economy, now sizeof(string) is 28 bytes in
32-bit environment instead of 4 bytes early.


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

* [Bug libstdc++/67503] String cannot be loaded from binary representation
  2015-09-08 16:28 [Bug libstdc++/67503] New: String cannot be loaded from binary representation radventure at yandex dot ru
                   ` (9 preceding siblings ...)
  2015-09-08 17:15 ` radventure at yandex dot ru
@ 2015-09-08 17:25 ` radventure at yandex dot ru
  10 siblings, 0 replies; 12+ messages in thread
From: radventure at yandex dot ru @ 2015-09-08 17:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from radventure at yandex dot ru ---
(In reply to radventure from comment #9)
> I understand the "small string optimization" idea. I agree about allocation
> counting. But I don't see space economy, now sizeof(string) is 28 bytes in
> 32-bit environment instead of 4 bytes early.

Now sizeof(string) is 24 bytes.


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

end of thread, other threads:[~2015-09-08 17:25 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-08 16:28 [Bug libstdc++/67503] New: String cannot be loaded from binary representation radventure at yandex dot ru
2015-09-08 16:32 ` [Bug libstdc++/67503] " redi at gcc dot gnu.org
2015-09-08 16:40 ` pinskia at gcc dot gnu.org
2015-09-08 16:54 ` radventure at yandex dot ru
2015-09-08 16:56 ` radventure at yandex dot ru
2015-09-08 17:03 ` redi at gcc dot gnu.org
2015-09-08 17:05 ` radventure at yandex dot ru
2015-09-08 17:08 ` radventure at yandex dot ru
2015-09-08 17:09 ` pinskia at gcc dot gnu.org
2015-09-08 17:12 ` pinskia at gcc dot gnu.org
2015-09-08 17:15 ` radventure at yandex dot ru
2015-09-08 17:25 ` radventure at yandex 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).