Archived
This forum has been archived. Please start a new discussion on GitHub.
slice2cpp produces bad code
in Bug Reports
slice2cpp generates bad C++ code while compiling the following Slice:
module Foo { class while { }; }
0
Comments
-
You don't show the bad code--what exactly do you think is wrong?
Because while is a C++ reserved word, it is mapped to _cpp_while. Is that what you are referring to? If so, that is expected; see the client-side C++ mapping in the manual.
Cheers,
Michi.0 -
I mean that if I compile such Slice with slice2cpp and then compile the generated
C++ code with some C++ compiler (gcc4 in my case) it won't compile due to errors.0 -
It would help to provide the exact compiler version, operating system, and finally compilation errors that you are getting.0
-
When I compile Sheff's slice code (after adding a semicolon in the last line) with slice2cpp 3.3.0 and try to compile the generated C++ code with g++ 4.2.4 on GNU/Linux (Kubuntu 8.04), the compiler reports the following error in line 381 of the generated header file:In file included from sl.cpp:13:
./sl.h:381: Fehler: »_cpp_while__staticInit« in Namensbereich »Foo« bezeichnet keinen Typ
(BTW, this looks suspiciously like the bug reported in post 14617 two years ago. )0 -
This is a bug in the code generator. Thanks for reporting this. We'll include a fix in the next release. As a work-around in the mean time, you can either rename the Slice symbol so it is no longer a C++ identifier, or you can edit the generated code. The line reading:
static ::Foo::_cpp_while__staticInit _while_init;
should instead bestatic ::Foo::while__staticInit _while_init;
Cheers,
Michi.0 -
By the way, C++ identifier in module name also produces bad code if
that module contain classes.0 -
Here is a patch that fixes the class name problem:
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 51ea19f..22a0334 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -3857,7 +3857,7 @@ Slice::Gen::ObjectVisitor::visitClassDefEnd(const ClassDefPtr& p) H << sp << nl << scoped << " _init;"; H << eb << ';'; _doneStaticSymbol = true; - H << sp << nl << "static " << scoped << "__staticInit _" << p->name() << "_init;"; + H << sp << nl << "static " << p->name() << "__staticInit _" << p->name() << "_init;"; } if(p->isLocal())
I'll have a look at the module name issue as well, thanks!
Cheers,
Michi.0 -
Thanks for the bug report. Here is a patch that fixes it:
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 22a0334..f990ccd 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -4460,7 +4460,8 @@ Slice::Gen::ObjectVisitor::emitOneShotConstructor(const ClassDefPtr& p) if(!allDataMembers.empty()) { - C << sp << nl << p->scoped().substr(2) << "::" << fixKwd(p->name()) << spar << allParamDecls << epar << " :"; + C << sp << nl << fixKwd(p->scoped()).substr(2) << "::" << fixKwd(p->name()) + << spar << allParamDecls << epar << " :"; C.inc(); DataMemberList dataMembers = p->dataMembers();
Cheers,
Michi.0