This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ [RFC] taking address of a static const data member



Section 9.4.2 of c++ standard "Static data members" does not directly address this issue. But there is
a dejagnu c++ test case which explicitly disallows (by issuing a link-time error) taking address of a static
const data member. Test case is const2.C.
This question has come up because, g++-4.0 (ppc-darwin target) issues the
same link error for the following test case (which requires taking address of Foo::foo).


#include <map>
struct Foo { static const int foo = 0x3ab; };
int main()
{
        std::map<int, int> m;
        m[Foo::foo];
}

And here is const2.C for easy reference:

/ { dg-do link }
// This test should get a linker error for the reference to A<int>::i.
// { dg-error "i" "" { target *-*-* } 0 }

template <class T> struct B { static const int i = 3; };
template <class T> struct A { static const int i = B<T>::i; };
const int *p = &A<int>::i;

int main(){}

So, is g++ correct in rejecting this seemingly good user code?

- Thanks, fariborz (fjahanian@apple.com)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]