I have been having problems with ICU’s rule-based Transliterator which turned out to be caused by a missing -O2 flag on debug builds using g++ 4.7.1. It was working fine when I did a release build (which had -O2), but when I built my project without that flag for debugging, the Transliterator object would never be created properly.
Transliterator* t = Transliterator::createFromRules(id, rules, UTRANS_FORWARD, parseError, status);
Without optimisation, t is assigned a null pointer and status is set to 32767, which translates to BOGUS UErrorCode when run through ICU’s u_errorName().
The first thing I tried was to remove the -g debug flag from my build, but that made no difference to what createFromRules() returned. Only when I added -O2 did it create the Transliterator object.
Testing indicates that -O1, -O2 and -O3 all work as expected, and only -O0 causes this to happen.
Can someone explain why this should be the case?
You should not have different results with/without debugging. Can you create a small test case including rules, give the ICU version and OS/platform, and file a ticket? 4.7.1 was released 2 months ago. Could be a compiler bug (ICU has a long history of finding those!!) or latent bug. You can link the bug to this question and vice versa.