Sign in to follow this  
Miss

Weird string behavior when using ?:

Recommended Posts

Encountered a weird behavior in string addition today on the latest SVN build:
 
string foo = "foo" + (true ? string("bar") : "bar");
string bar = "foo" + (false ? "bar" : string("bar"));
string foobar = "foo" + (true ? "bar" : "bar");
print(foo); // barbar
print(bar); // foobar
print(foobar); // foobar
The obviously-broken case here is the first one, which turns into "barbar". I wasn't able to reproduce this with integers or a simple script class with an opAdd method, so perhaps this is exclusive to the scriptstdstring addon?

Share this post


Link to post
Share on other sites
Just ran into another string-related issue, perhaps it's related. The following never passes:
 
if (wButton.m_func == "scenario " + m_currentScenario.GetID())
Neither does this:
 
string id = m_currentScenario.GetID();
if (wButton.m_func == "scenario " + id)
But this DOES pass:
 
string id = "scenario " + m_currentScenario.GetID();
if (wButton.m_func == id)
Here, wButton.m_func is defined in scripts, and GetID() is a method registered by C++ with declaration "string GetID()".

This seemed to have started happening after updating the WIP SVN version (we were already using the WIP version before but we were a little behind).

Share this post


Link to post
Share on other sites

I've fixed this now in revision 2368.

 

All of the scenarios were caused by the same bug. A temporary variable was being overwritten when invoking overloaded operators with left-to-right evaluation. This bug was introduced in the WIP itself. Good thing you identified the problem before I released the new version. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this