0

Having an issue getting this syntax to compile using the Visual Studio Nov 2012 CTP C++ Compiler ... Just wanted to be sure I wasn't missing something obvious.

Thanks!

EDIT: Removed Header to make it even simpler.

class Location
{
public:
    Location();
};

class Shape
{
public:
    Shape();
    Shape(Location location);
};


// Doing this by pointer works ...
// Shape::Shape(Location* location){}
// Shape::Shape() : Shape(new Location()){}

Shape::Shape(Location location)
{
}

Shape::Shape()
    : Shape(Location())
    // error C2143: syntax error: missing ';' before ':'
{
    // int x = 0;
    // (void) x;  // Added these two lines in some cases to get it to compile.
    // These two lines do nothing, but get around a compiler issue.
}
e.s. kohen
  • 213
  • 1
  • 4
  • 21
  • 4
    If it's an internal error in the compiler then it means that the compiler is messing up, not your code. Looks to me that it's correct. You might want to file a bug report at MSDN. – Seth Carnegie Jan 16 '13 at 21:43
  • 6
    An internal error should *never* occur. If it does, it's always a bug ion the compiler, and never your fault. – Kerrek SB Jan 16 '13 at 21:43
  • 2
    As a sidenote/pet peeve, using `void` to indicate functions take no arguments... **AUGH**! – Nik Bougalis Jan 16 '13 at 21:48
  • 3
    You also forgot all the semicolons. Maybe your compiler just got angry with you and wanted you to leave it alone. – Kerrek SB Jan 16 '13 at 21:49
  • 2
    I guess this is not real code, missing semicolon, no forward declaration etc. – billz Jan 16 '13 at 21:50
  • @Kerrek, sorry yeah.. I was trying to simplify.. I fixed it though. :p – e.s. kohen Jan 16 '13 at 21:57
  • One thing to try is to look for missing semicolons in your real code. I've got the 2012 compiler (not the CTP) to crash with internal errors when I missed syntactic elements in complex template definitions. – Peter Ruderman Jan 16 '13 at 22:02
  • @SethCarnegie I looked on Connect to see if there was a way, but I couldn't find the product. You have any suggestions? – e.s. kohen Jan 16 '13 at 22:03
  • @PeterRuderman I know it is not missing semicolons as the code compiles and runs just fine when I don't include the syntax for constructor delegation, (unless that syntax requires a semicolon that I don't know about). Does this work with GCC? Sigh. I need to get gcc installed again. – e.s. kohen Jan 16 '13 at 22:05

1 Answers1

2
// .h Simplification
class Location
{
public:
  Location() {}
  Location(Location const& other) {}
};

class Shape
{
  Shape();
  Shape(Location location);
};

// How about by value or reference?
Shape::Shape(Location location)
{
}

Shape::Shape(void)
  : Shape(Location()) // error C1001: An internal error has occurred in the compiler.
{
}

int main() {}

The above code compiles and runs in gcc 4.7.2

I had to make a few changes to your code to make it compile. When simplifying things, try to keep the simplified code compiling. http://sscce.org/

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524
  • What's with the multiple copies? – David G Jan 16 '13 at 22:41
  • @Yakk I am getting the same exact errors with your code and mine. Since it works on GCC, and now that I have just been told that the latest version of the compiler, post CTP compiles this cleanly, I will chalk it up to a bug in the CTP compiler. Otherwise, it appears to be valid syntax. And I will mark your's as the answer for validating that it is proper C++ 11 syntax. Thanks! – e.s. kohen Jan 16 '13 at 23:12
  • New Addition: I can't count the number of different bugs that I have gotten with this syntax, but they all usually end up in some unknown compiler error, or an error that VS cannot communicate with some child process. I have managed to get this to compile by adding in: int x = 0; (void) x; into each of my constructors that delegate to others. Don't ask me why it works, it just does, and I am using it as a workaround until release. Voodoo! – e.s. kohen Jan 17 '13 at 02:52