News for hackers. Stuff that matters.
Re:GCC starts move towards implementation in C++ by stingraycharles on Monday May 31, 2010 @11:37AM (#1392707)
I find this statement particularly interesting:

For example, I think constructors and destructors are pretty easy and hard to misuse.

Now, I am aware that the competence of the average GCC committer probably exceeds that of the average programmer, but still, constructors and destructors are easy to misuse: throwing an exception in the constructor comes to mind, in which case the destructor isn't called. Anything about C++ can be probably misused in the hands of the inexperienced.

Other than that, I think this is a good move, and it'll be interesting to see how this develops. There probably are a lot of (heavy) opinions on this inside the GCC community, and it it'll be interesting to see which directions they choose to go.

Re:GCC starts move towards implementation in C++ by devinj on Monday May 31, 2010 @11:42AM (#1392716)
throwing an exception in the constructor comes to mind

I don't know C++ and thus don't know all the different ways to break constructors and destructors, but this particular way will be banned-- exceptions are off-limits.

I kind of think that the worst part of all of this will not be the C++ code that is added to gcc, but the massive bikeshedding that looks to be inevitable at the start.

Re:GCC starts move towards implementation in C++ by stingraycharles on Monday May 31, 2010 @12:06PM (#1392794)
Yes, that would indeed be the case if they compiled with -fno-exceptions, which they just might do indeed, - otherwise, you can still cause exceptions to be thrown without using them yourself (for example, if you're out of memory, 'new Foo ()' causes a std::bad_alloc () exception to be thrown).

And yes, I feel for the people in the GCC community that have to lead the team through this process of coming up with an acceptable policy most people agree with. I'm pretty sure it will be a challenging task with lots of egos colliding.

Re:GCC starts move towards implementation in C++ by rwmj on Monday May 31, 2010 @05:36PM (#1393554)
Why wouldn't a compiler just abort if it runs out of memory? A compiler seems to be a short running program -- I wouldn't even bother too much freeing up allocated memory.
Re:GCC starts move towards implementation in C++ by scott_s on Monday May 31, 2010 @05:52PM (#1393589)

    PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
  19087 scschnei  25   0  412m 333m 5480 R  100 16.6   0:07.62 cc1plus
Your C++ compiler would be unusable for some modern C++ programs. You're judging how you expect a compiler to behave based on how you've used them in the past. C++ with heavy template meta-programming (like what I was compiling there) can take an enormous amount of memory and CPU time to finish.
Re:GCC starts move towards implementation in C++ by boris on Monday May 31, 2010 @03:01PM (#1393188)
throwing an exception in the constructor comes to mind, in which case the destructor isn't called

Of course it is not called -- the object has failed to construct. There is no object. You cannot call a destructor on nothing. Now if some data member has been constructed but the call constructor failed, destructors for such members will be called.

Re:GCC starts move towards implementation in C++ by stingraycharles on Monday May 31, 2010 @04:05PM (#1393351)
The constructor might be partially executed before the exception is thrown (for example, allocated memory or locked resources), in which case those things don't get cleaned up.

I'm not arguing it isn't correct behavior, it's just that things don't always seem as easy and straightforward as they look on first sight.

Re:GCC starts move towards implementation in C++ by palish on Monday May 31, 2010 @03:32PM (#1393257)
So don't use exceptions. They're not needed and definitely make C++ code far more complicated, not less.
Re:GCC starts move towards implementation in C++ by mrvir on Monday May 31, 2010 @02:36PM (#1393142)
Interesting indeed. It's good that GCC people start eating their own dog food and allow the use of C++. I'm sure this move will bring improvements to g++.
Re:GCC starts move towards implementation in C++ by danudey on Monday May 31, 2010 @07:52PM (#1393835)
And if they have any issues, they could start compiling GCC with LLVM. I hear Clang's implementation of C++ is pretty fast, and it could help track down bugs in both suites.

That is, assuming that GCC doesn't use a ton of GCC-specific extensions, which I'm fairly certain they do.