On Sun, Feb 10, 2013 at 1:38 AM, john skaller <skal...@users.sourceforge.net> wrote: > Grrr .. why is C++ syntax so completely bad that most compilers > cannot get it right??? Stupid committee trying to avoid extra keywords... > > This works with gcc 4.2.1 and with clang 3.3: > > > ((::std::string*)(&tmp))->::std::basic_string<char>::~basic_string<char>(); > > but not with: > > g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 > > Instead I get this: > > /home/skaller/.felix/cache/text/home/skaller/felix/build/release/tools/flx_grep.cpp: > In function ‘size_t RE2_decoder(void*, char*, size_t)’: > /home/skaller/.felix/cache/text/home/skaller/felix/build/release/tools/flx_grep.cpp:24:77: > error: expected class-name before ‘(’ token > > The funny thing is that the template: > > template<class T> void destroy (T *p) { p->~U; } > > usage: > > destroy<string>(); > > always works. Isn't there a standard template for that? > Anyone know what the proper C++ syntax is?
I think it's a gcc 4.6.3 bug that it doesn't accept your original code, but that's overcomplicated code anyway. It compiles cleanly with gcc version 4.8.0 20121026 (experimental) (GCC), my 4 month-old gcc build. The template version has clues to simple syntax that's more portable to older/buggier compilers -- drop the qualification, the lookup is already in the scope of p's type, and you don't need to write out basic_string<char> when you already have a handy typedef either, the ->~Typename Here are some options that work with gcc 4.6.3 and clang 3.0 at least: ((::std::string*)(&tmp))->std::basic_string<char>::~basic_string(); ((::std::string*)(&tmp))->~basic_string<char>(); ((::std::string*)(&tmp))->~basic_string(); Qualification is unnecessary as the lookup starts in ::std::string, and the injected class name is implicitly basic_string<char>. -- James ------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language