Different GNU/SUN implementations of template argument deduction?

S

supervixen

I have two overloads of function g :

template<class T> void g (const T* t) { t->foo(); }
template<class T> void g (const T& t) { t.foo(); }

And the following lines of code

C* pc;
g(pc);

produce this error when built with GCC,

......In member function 'void g(const T&) [with T = C*]'.....
....."request for member 'foo' in 'pc' which is of non-class type 'C*
const'

which, on the other hand, compiles, links and executes with no errors
on CC


My configuration is
CC: Sun C++ 5.9 SunOS_sparc Patch 124863-04)
gcc: GCC 3.4.3 csl-sol210-3_4-branch+sol_rpath
dmake : Sun Distributed Make 7.8 SunOS_sparc Patch 126503-01
and i'm working on a Sun OS 5.10, Sparc machine, obviously:)

Any helps will be appreciated!
 
M

Maxim Yegorushkin

supervixen said:
I have two overloads of function g :

template<class T> void g (const T* t) { t->foo(); }
template<class T> void g (const T& t) { t.foo(); }

And the following lines of code

C* pc;
g(pc);

produce this error when built with GCC,

.....In member function 'void g(const T&) [with T = C*]'.....
...."request for member 'foo' in 'pc' which is of non-class type 'C*
const'

which, on the other hand, compiles, links and executes with no errors
on CC

My configuration is
CC: Sun C++ 5.9 SunOS_sparc Patch 124863-04)
gcc: GCC 3.4.3 csl-sol210-3_4-branch+sol_rpath
dmake : Sun Distributed Make 7.8 SunOS_sparc Patch 126503-01
and i'm working on a Sun OS 5.10, Sparc machine, obviously:)

gcc is correct.

For g() overloads the following conversion chains are compared (note, that when
you put const on the right of the type it always makes things easier to understand):

(lvalue)C* -> C const*
(lvalue)C* -> C* const&

The first chain requites a conversion of the argument type, the second chain
does not convert the argument type, thus the second overload is chosen.

Sun CC compiler is well known for its non-conformance to the C++ standard, don't
trust it, double check with gcc/g++.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top