Why do G++ and MSVS handle s1 += " world!" differently?

This is a discussion on Why do G++ and MSVS handle s1 += " world!" differently? within the C++ Programming forums, part of the General Programming Boards category; This thread is related to this thread: Memory leak in Soln8_05.cpp from Ivor Horton's Beginning Visual C++ 2008 book? .
...

Why do G++ and MSVS handle s1 += " world!" differently?

I basically stuck debug output statements all through a modified copy of the author's solution for one of the chapter exercises in an effort to dissect what constructors, destructors and overloaded functions were being used.

1) MSVC is doing it by the book. I am guessing that g++ is applying optimizations here. Try running the MSVC build in Release mode.
2) Because there is no operator += that takes a const char*. However, there is one operator that takes a const CSimpleString&. So the compiler checks the constructors to see if there is CSimpleString(const char*), and there is. So it invokes that to create a temp object, and then calls operator +=. This is called an implicit conversion.

g + + seems to be the construction / destruction of the temporary return of the object on the Op Op wegzuoptimieren + + =.
Because of such things (The standard explicitly allows such optimizations) you should turn off all optimizations when debugging.
By the way: Why did you build the Op + = with the help of the Op + and not the other way, as recommended?

Please keep to English on the boards. This is supposed to be an international forum, and you are basically destroying the ability to read what you write for 99% of the people. So unless you have a very special reason for using german, do please refrain from doing so.

unless you have a very special reason for using german, do please refrain from doing so.

I did have a reason.
Looking at deoren's web site I had reason to assume that he might speak german.
I used german to say something I couldn't have said nearly as clearly in english (since english is not my mother tongue).

Don't you think that you are overreacting a little?

PS: Is this site about helping each other or about using the right language?
You said it yourself: "This is supposed to be an international forum".

No, international as in "english."
I posted that as both as a reminder (there are people who don't know) and as a message to others who read it should they wish to use a non-english language.
I'm not overreacting as in "stop doing this or else." It was simply a little reminder. Now that that's done, you can do what you want.

Compilers are allowed to perform optimisation to avoid copy-construction in certain cases.
As such, the standard says that you're not allowed to rely on side-effects that occur during copy-construction. Outputting any kind of debug message is a side-effect. In both cases, any temporary object that is created is of course destructed.
Just remove any logging you have and the problem is gone. Yes the compilers optimised differently, but the net result is code that has the same effect. Of course if your code is broken, then no matter what the compiler does, your code might not work.

There are a lot of differences between compilers and this is very much not one of the differences between compilers that you should worry about. There are far bigger issues that you'll run into eventually if using multiple compilers.

Edit: Please keep it in English. It's not fair to exclude a large portion of the posters who cannot read other languages. Posting in a different language could mean that you are giving totally wrong advice and without anyone else to understand and refute your post, the originaly poster could be very much sent down the wrong path.
You might say that it is unfair that this site be for English speakers, but I'm sure you could find a German programming site if you wanted to, and like it or not, C and C++ are English programming languages.

Edit: Please keep it in English. It's not fair to exclude a large portion of the posters who cannot read other languages. Posting in a different language could mean that you are giving totally wrong advice and without anyone else to understand and refute your post, the originaly poster could be very much sent down the wrong path.
You might say that it is unfair that this site be for English speakers, but I'm sure you could find a German programming site if you wanted to,

Please read my answer to Elysia.

Originally Posted by iMalc

and like it or not, C and C++ are English programming languages.

No offence intended. But that's complete nonsense. Like we could only use latin to talk about medicine.

The reason the forum uses English is because more people speak it and because the forum isn't a personal help service. By that I mean it's important that more than one person, the OP, understands what's being said, for reasons that have already been explained. Personally I don't care since a translation has been provided, as shabby as it is. Except I hope we don't have to rely on people translating to English when there is an Indian on the forum, or someone from the Middle East. We simply do not have the resources to provide help in as many languages as possible like some sort of instruction leaflet.

Not to mention rule 7:
Please construct posts with content that furthers the community

And by excluding a big part of the community (by using a language that most people probably don't know) I think there is little doubt that content does not further the community. English is the standard language to use here.

I think Elysia means that this forum is used by people internationally. We use English to understand each other, that's all, and no one said you had to be silent. I don't know why you elected to use German other than you saw the opportunity, even though this person writes fluently. But it's important that people who don't speak German understand.

(the fact that I obviously didn't manage to make myself clear yet ultimately supports my point here)

If this is supposed to be an english only forum it should be stated clearly. And I would gladly stay (far) away.

I use english in forums like this almost always, because it is the lingua franca of our time. But when I hit a point when my english fails my communication needs I use what enables me to express myself. Believe it or not, I even use latin phrases sometimes.

If that's inacceptable, only native english speakers should be granted full membership...