[great-users] Small bug - SetStrValue is not checked...

Gabor Karsai gabor at isis.vanderbilt.edu
Wed Apr 7 16:03:07 CDT 2004


Tivadar,

How about the "1-step silent type conversion" feature of C++?
I'm sure that "string" has a constructor "string(const char*)" and 0
type-matches const char*.
Try this:
#include <string>

void foo(const std::string & clunk)
{
	std::string me = clunk;
}

void bar()
{
	foo(0);
}

Cheers,
-- Gabor
> -----Original Message-----
> From: Tivadar Szemethy 
> Sent: Wednesday, April 07, 2004 1:45 PM
> To: great-users
> Subject: RE: [great-users] Small bug - SetStrValue is not checked...
> 
> 
> > I'm using the officially unreleased version of GReAT. I was not
> careful
> > enough and tried the following thing in an attribute mapping:
> > 
> > <something>.SetStrVale("something", 0);
> > 
> > Obviously it should be:
> > 
> > <something>.SetStrVale("something", "0");
> > 
> > No errors are reported during configuration and the 
> execution of this 
> > rule crashes GME.
> 
> This is kind of strange. SetStrValue has signature
> bool SetStrValue(string strAttrName, const string& value);
> 
> and the compiler MUST NOT accept an integer zero for &value, 
> since 0 cannot be cast into a string reference.
> 
> Even if it was not a zero, you should get some kind of error 
> unless you cast explicitly, and even so you have to figure 
> out a trikcy cast to outwit the compiler. If I try something 
> similar, I get the expected error:
> 
> Gz__SMOLES2UPPAAL-gr.cpp(37) : error C2664: 'GetStrValue' : 
> cannot convert parameter 2 from 'const int' to 'class 
> _STL::basic_string<char,struct std::char_traits<char>,class 
> _STL::allocator<char> > &'
>         A reference that is not to 'const' cannot be bound to 
> a non-lvalue NMAKE : fatal error U1077: 'cl.exe' : return code '0x2'
> 
> 
> >[Adi]
> >The AttributeMapping and Guard code is compiled into a dll by GRE and
> >called at run time. Since the code you wrote is valid C++ code it is
> >successfully compiled and linked. In your case it's a semantic error
> >that even the C++ compiler cannot catch.
> 
> I disagree, see above.
> 
> Tivadar
> 
> _______________________________________________
> great-users mailing list
> great-users at list.isis.vanderbilt.edu
> http://list.isis.vanderbilt.edu/mailman/listinfo/great-users
> 


More information about the great-users mailing list