[cfe-dev] private class members access fails with meta-programming in clang?

Ramneek Handa ramneekhanda at gmail.com
Wed Apr 24 09:20:35 PDT 2013


I thought this should pass with clang.

x-- start --x
  
#include <boost/mpl/has_xxx.hpp>

BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(hasSomething, Data, false);

class A {
private:
struct Data {
};
};


void function(bool val = hasSomething<A>::value) {}


x-- end --x

however it produces following output:
test_private_data.cpp:3:49: error: 'Data' is a private member of 'A'
BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(hasSomething, Data, false);
^
/usr/include/boost/mpl/has_xxx.hpp:195:68: note: expanded from macro 'BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF'
, boost::mpl::aux::type_wrapper<BOOST_MSVC_TYPENAME U::name>* = 0 \
^
test_private_data.cpp:3:1: note: while substituting deduced template arguments into function template 'test' [with U = A]
BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(hasSomething, Data, false);
^
/usr/include/boost/mpl/has_xxx.hpp:193:41: note: expanded from macro 'BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF'
static boost::mpl::aux::yes_tag test( \
^
test_private_data.cpp:12:26: note: in instantiation of template class 'hasSomething<A, mpl_::bool_<false> >' requested here
void function(bool val = hasSomething<A>::value) {}
^
1 error generated.
/usr/bin/ld: /tmp/test_private_data-Hatffv.o: No such file: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)




BUT it passes with GCC.

Which one is right?
-RH






More information about the cfe-dev mailing list