Boost logo

Boost :

Subject: Re: [boost] Complier bug taking the address of an instantiated member function template ?
From: Edward Diener (eldiener_at_[hidden])
Date: 2011-03-15 16:31:22


On 3/15/2011 4:10 PM, Doug Gregor wrote:
> On Tue, Mar 15, 2011 at 1:01 PM, Edward Diener<eldiener_at_[hidden]> wrote:
>> Apologies as this is off-topic, as it refers to C++ and not Boost, but I
>> have run into this working with my TTI library in the sandbox and hopefully
>> some Boost developer has run into this and can tell me whether all compilers
>> are broken or I am doing something completely wrong in my use of C++ syntax:
>>
>> The code:
>>
>> "struct AType
>> {
>> double SomeFunc(int,long *,double&) { double ret(0); return ret; }
>> template<class X,class Y,class Z,short AA> double SomeFuncTemplate(X,Y *,Z
>> &) { double ret(AA); return ret; }
>> };
>>
>> template
>> <
>> class T
>> >
>> struct TTest
>> {
>> typedef char Bad;
>> struct Good { char x[2]; };
>> template<T> struct helper;
>> static Good check(helper<&AType::template
>> SomeFuncTemplate<int,long,double,50> > *);
>> static Bad check(...);
>> static const bool value=sizeof(check(0))==sizeof(Good);
>> };
>>
>> template
>> <
>> class T,
>> class C
>> >
>> struct TTest1
>> {
>> typedef char Bad;
>> struct Good { char x[2]; };
>> template<T> struct helper;
>> template<class U> static Good check(helper<&U::SomeFunc> *);
>> template<class U> static Bad check(...);
>> static const bool value=sizeof(check<C>(0))==sizeof(Good);
>> };
>>
>> template
>> <
>> class T,
>> class C
>> >
>> struct TTest2
>> {
>> typedef char Bad;
>> struct Good { char x[2]; };
>> template<T> struct helper;
>> template<class U> static Good check(helper<&U::template
>> SomeFuncTemplate<int,long,double,50> > *);
>> template<class U> static Bad check(...);
>> static const bool value=sizeof(check<C>(0))==sizeof(Good);
>> };
>>
>> int main()
>> {
>>
>> static_assert(TTest
>> <
>> double (AType::*)(int,long *,double&)
>> >::value,
>> "failure in TTest"
>> );
>>
>> static_assert(TTest1
>> <
>> double (AType::*)(int,long *,double&),
>> AType
>> >::value,
>> "failure in TTest1"
>> );
>>
>> static_assert(TTest2
>> <
>> double (AType::*)(int,long *,double&),
>> AType
>> >::value,
>> "failure in TTest2"
>> );
>>
>> return 0;
>>
>> }"
>>
>> Both gcc 4.5.2 ( with -std=c++0x ) and msvc 10.0 put out the static assert
>> "failure in TTest2". I do not see why this is happening. I have no tried
>> clang, but if I could figure out how to use it in Windows I would.
>>
>> Anyone ?
>
> The code looks well-formed to me; Clang accepts it.

Thanks, I will post this on gcc and VC++ NGs/Forums and see what people
say there. Strange that both should work incorrectly.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk