[tti] compiler error: shadows template param `class T`

Hello, The TTI library macros expand to code that uses naive template parameter names like "T", "F", "U", etc. The library implementation should be changed to use library reserved names to avoid clashing with user template parameter names. For example, the library use a name like boost_tti_aux_T (or even better BOOST_PP_CAT(boost_tti_aux_T_, __LINE__)) instead of T and state in the documentation that any name prefixed by boost_tti_aux (in any namespace) is reserved for the library implementation. The same should be done for any other implementation symbol defined by the TTI library. This is an issue if the macros are expanded for example within a class (which is and should be possible after changing them not to expand in the boost::tti namespace). For example, assuming BOOST_TTI_HAS_COMP_MEMBER_FUNCTION is fixed not to expand in boost::tti then the following: template< typename T > struct myvector { BOOST_TTI_HAS_COMP_MEMBER_FUNCTION_TRAIT(has_push_back, push_back) // expand to code using a template parameter naively named T ... }; Will generate a compiler error on GCC "error: shadows template param class T". --Lorenzo

On 8/10/2011 9:37 PM, Lorenzo Caminiti wrote:
Hello,
The TTI library macros expand to code that uses naive template parameter names like "T", "F", "U", etc. The library implementation should be changed to use library reserved names to avoid clashing with user template parameter names. For example, the library use a name like boost_tti_aux_T (or even better BOOST_PP_CAT(boost_tti_aux_T_, __LINE__)) instead of T and state in the documentation that any name prefixed by boost_tti_aux (in any namespace) is reserved for the library implementation. The same should be done for any other implementation symbol defined by the TTI library.
This is an issue if the macros are expanded for example within a class (which is and should be possible after changing them not to expand in the boost::tti namespace). For example, assuming BOOST_TTI_HAS_COMP_MEMBER_FUNCTION is fixed not to expand in boost::tti then the following:
template< typename T> struct myvector { BOOST_TTI_HAS_COMP_MEMBER_FUNCTION_TRAIT(has_push_back, push_back) // expand to code using a template parameter naively named T ... };
Will generate a compiler error on GCC "error: shadows template param class T".
This is a good suggestion, which I will implement. Thanks for bringing it up.

Edward Diener-3 wrote:
On 8/10/2011 9:37 PM, Lorenzo Caminiti wrote:
Hello,
The TTI library macros expand to code that uses naive template parameter names like "T", "F", "U", etc. The library implementation should be changed to use library reserved names to avoid clashing with user template parameter names. For example, the library use a name This is a good suggestion, which I will implement. Thanks for bringing it up.
Thanks! Also another thing, I don't remember if the docs explain the library behavior with cv-qualified member functions-- I should probably go back and read the docs instead of just asking you :) I did test cv-qualified member function introspection and it seems to be working fine (as it should). If it's not documented, can you please document it? The same would apply to cv-qualified member data (which I didn't test). For example: struct C { void f () const {} void g () const volatile {} }; BOOST_TTI_HAS_COMP_MEMBER_FUNCTION_TRAIT(has_f, f) has_f< void (C::*)() >::value // 0 has_f< void (C::*)() const >::value // 1 has_f< void (C::*)() volatile >::value // 0 has_f< void (C::*)() const volatile >::value // 0 BOOST_TTI_HAS_MEMBER_FUNCTION_TRAIT(has_g, g) has_g< C, void >::value // 0 has_g< C const, void >::value // 0 has_g< C volatile, void >::value // 0 has_g< C const volatile, void >::value // 1 Thanks. --Lorenzo -- View this message in context: http://boost.2283326.n4.nabble.com/tti-compiler-error-shadows-template-param... Sent from the Boost - Dev mailing list archive at Nabble.com.

On 8/11/2011 10:41 AM, lcaminiti wrote:
Edward Diener-3 wrote:
On 8/10/2011 9:37 PM, Lorenzo Caminiti wrote:
Hello,
The TTI library macros expand to code that uses naive template parameter names like "T", "F", "U", etc. The library implementation should be changed to use library reserved names to avoid clashing with user template parameter names. For example, the library use a name This is a good suggestion, which I will implement. Thanks for bringing it up.
Thanks!
Also another thing, I don't remember if the docs explain the library behavior with cv-qualified member functions-- I should probably go back and read the docs instead of just asking you :) I did test cv-qualified member function introspection and it seems to be working fine (as it should). If it's not documented, can you please document it? The same would apply to cv-qualified member data (which I didn't test).
For example:
struct C { void f () const {} void g () const volatile {} };
BOOST_TTI_HAS_COMP_MEMBER_FUNCTION_TRAIT(has_f, f)
has_f< void (C::*)()>::value // 0 has_f< void (C::*)() const>::value // 1 has_f< void (C::*)() volatile>::value // 0 has_f< void (C::*)() const volatile>::value // 0
BOOST_TTI_HAS_MEMBER_FUNCTION_TRAIT(has_g, g)
has_g< C, void>::value // 0 has_g< C const, void>::value // 0 has_g< C volatile, void>::value // 0 has_g< C const volatile, void>::value // 1
I will add some discussion in the docs about CV-qualified member function and data. Thanks ! Eddie
participants (3)
-
Edward Diener
-
lcaminiti
-
Lorenzo Caminiti