I thought the delegating constructors addition to c++11 was great. Not something I'd need all the time, but it'd probably come in handy once in a while. But as always, there's a hole.
The standard specifies that if a constructor delegates to itself, the program is ill-formed. It also states that in that case no diagnostic is required.So given something like this:
Ref: thenewcpp.wordpress.com
class C { public: C() { } C(int aval) : C('i') { } C(char) : C(42) { } } ; int main(int N, char ** S) { C test(1) ; return 0 ; }gcc 4.8 compiles without warning, and then crashes when you run. Thankfully clang does better:
testerror.cpp:9:13: error: constructor for 'C' creates a delegation cycle [-Wdelegating-ctor-cycles]I think there's a serious chance that gcc could be irrelevant in the coming future.C(char) : C(42) { } ^testerror.cpp:8:3: note: it delegates toC(int aval) : C('i') { } ^testerror.cpp:9:3: note: which delegates toC(char) : C(42) { } ^1 error generated.
Labels: c++, c++11, programming
Feb '04
Oops I dropped by satellite.
New Jets create excitement in the air.
The audience is not listening.
Mar '04
Neat chemicals you don't want to mess with.
The Lack of Practise Effect
Apr '04
Scramjets take to the air
Doing dangerous things in the fire.
The Real Way to get a job
May '04
Checking out cool tools (with the kids)
A master geek (Ink Tank flashback)
How to play with your kids