x3 static initialisation problems

Dirk Bonekämper <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
Hello,

I did create a x3 project using boost 1.60 at the time. This project
contains several separately compile rules.

When I got back to it recently I updated to 1.65.1. And I got hit
immediately with the "uninitialized rule" assert in
traits::get_info<>().

Looking at the myrule_def.hpp file, I realized that the static myrule
object gets returned by reference in the parser::myrule() function.
Of course that's subject to the static initialization order fiasco.

So I checked the calc9 expression_def example file to see how the
examples handled the problem. I saw that the static object still
gets returned by reference. But now a static symbol parser is also
inititialized by the parser::myrule() function. So now the function may
try to modify an object that hasn't even started it's lifetime yet.  

My solution: Return reference to rule from a Meyers singlenton. Keep
symbol initialization within the static section like in 1.60. 

Caveat: I still need to keep a namespace myrule object as the
BOOST_SPIRIT_DEFINE_ macro expects it. The macro only uses the name
in decltype(name), so maybe the macro could be changed to use
PP_CAT(rule_name, _type) to generate the type of the rule.

Cheers, Dirk


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.