GarageGames / Torque3D

MIT Licensed Open Source version of Torque 3D from GarageGames
http://torque3d.org
MIT License
3.35k stars 1.2k forks source link

Type safety of StringTableEntry #1965

Open elfprince13 opened 7 years ago

elfprince13 commented 7 years ago

As the engine currently stands, StringTableEntry is a simple typedef on const char *. We might consider making it a POD struct with an implicit conversion TO const char *, but no explicit conversion FROM const char *. This would allow the compiler to eliminate a large class of potential bugs where somebody passes a wild c-string into a method expecting an actual StringTableEntry.

elfprince13 commented 7 years ago

Started a branch to work on this: https://github.com/elfprince13/Torque3D/commit/595917ab7b20153cb09d2bb6c5eb8e9b3acdf40f#diff-637773112ccf1788179bc28c358075e0 . Already turned up a handful bugs. Unfortunately for every error about calling the private const char * constructor, I get two dozen about passing non-simple types through varargs.

elfprince13 commented 7 years ago

Okay: this is looking a bit better now that I'm conforming to the trivial type spec, but I'm starting to get deep into the engine, and scary things are popping up (like...the lexer!).

Areloch commented 7 years ago

Hm, not a bad idea. Preventing inadvertently tossing around regular strings into it would curb some bad habit behavior.