Hi
Ice 3.3 (slice2html), Ice 3.4.1 (slice2java, slice2py, slice2cs), any compiler, Mac OS X/FreeBSD/Linux, MCPP V.2.7.2 (2008/11)
Consider the following slice:
Code:
#ifndef MY_MODULE_ICE
#define MY_MODULE_ICE
module MyModule
{
struct foo
{
string bar; // foobar
};
};
#endif
This compiles fine using slice2cpp, slice2rb, and slice2php, but fails under slice2py (also Ice.loadSlice), slice2java, slice2cs, and slice2html giving the following error:
Code:
[dev@bsd /tmp]$ slice2py test2.ice
/tmp/test2.ice:9: struct `foo' must have at least one member
[dev@bsd /tmp]$
The Ice manual states:
4.5.1 Comments
Slice definitions permit both the C and the C++ style of writing comments:
/*
* C-style comment.
*/
// C++-style comment extending to the end of this line.
so I assume this is misbehavior in the parser of those slice compilers.
All compilers that fail actually set "keepComments" to true in their call to Slice::Preprocessor:: preprocess(bool). This leads to the call to mcpp set the "-C" flag, which in turn keeps comments in the output.
I've checked the preprocessor output of slice2py and realized, that the preprocessor is moving the comment to the wrong position:
Code:
[dev@bsd /tmp]$ slice2py -E test2.ice
#line 1 "/tmp/test2.ice"
module MyModule
{
struct foo
{
// foobar string bar;
};
};
Yikes! Calling mcpp on the command line directly yields the same results:
Code:
[dev@bsd /tmp]$ mcpp -C test2.ice
#line 1 "/tmp/test2.ice"
module MyModule
{
struct foo
{
// foobar string bar;
};
};
I'm not certain if this really intended by mcpp or a bug at that end (it happens in mcpp 2.7.2, on both MacOS and FreeBSD). Running mcpp in OLD mode (-@old) resolves the issue, but I', not certain if this lead to other problems.
Code:
[dev@bsd /tmp]$ mcpp -@old -C test2.ice
#line 1 "/private/tmp/test.ice"
module MyModule
{
struct foo
{
string bar; // foobar
};
};
I just realized, that the comment features were introduced in Ice 3.4.0, that's why we didn't see that issue earlier (the same problem exists when calling slice2html on Ice 3.3):
The Slice compilers for Java, C#, and Python now preserve Slice comments in the generated code.
So I would suggest one of the following solutions:
- Contact the authors of mcpp, if you assume this is an mcpp bug
- Add 'args.push_back("-@old");' at line 153 of cpp/Slice/Preprocessor.cpp (if @old doesn't 't break other things)
- Call Slice::Preprocessor:: preprocess passing "false" instead of true (probably not want you really want)
- Change all slice compilers to call preprocess with keep comments set to true (so this way at least they behave identically)
- Make same line C++ style comments illegal (yikes!)
Cheers
Michael