www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - bug?

↑ ↓ ← "DigitalMars" <suff beotel.yu> writes:
greetings...

following does not compile... (scppn 8.40.2n)

template<typename T,T (*Init)()> T tmpl()
{
    static T mT(Init());
    return mT;
};

void* func()
{
    return 0;
};

int main()
{
    void* X=tmpl<void*,func>();
    return 0;
};

gives:
void* X=tmpl<void*,func>();
                         ^
equinoxtest.cpp(14) : Error: need explicit cast to convert
from: void *(*C func)()
to  : T(*C func)()
equinoxtest.cpp(5) : Error: need explicit cast to convert
from: T
to  : void *
void* X=tmpl<void*,func>();
                         ^
equinoxtest.cpp(14) : Error: need explicit cast to convert
from: void *(*C func)()
to  : T(*C func)()
--- errorlevel 1

not sure if this is known issue and if this actually is valid ansi code or
not

Suff
Aug 10 2004
↑ ↓ "Matt Morgan" <geckofood yahoo.com> writes:
Try checking "Relax Type Checking" in the project compiler settings tab
(GUI) or use the -Jm option (cmdline).

"DigitalMars" <suff beotel.yu> wrote in message
news:cfbpqo$15eb$1 digitaldaemon.com...
 greetings...

 following does not compile... (scppn 8.40.2n)

 template<typename T,T (*Init)()> T tmpl()
 {
     static T mT(Init());
     return mT;
 };

 void* func()
 {
     return 0;
 };

 int main()
 {
     void* X=tmpl<void*,func>();
     return 0;
 };

 gives:
 void* X=tmpl<void*,func>();
                          ^
 equinoxtest.cpp(14) : Error: need explicit cast to convert
 from: void *(*C func)()
 to  : T(*C func)()
 equinoxtest.cpp(5) : Error: need explicit cast to convert
 from: T
 to  : void *
 void* X=tmpl<void*,func>();
                          ^
 equinoxtest.cpp(14) : Error: need explicit cast to convert
 from: void *(*C func)()
 to  : T(*C func)()
 --- errorlevel 1

 not sure if this is known issue and if this actually is valid ansi code or
 not

 Suff

Aug 11 2004
↑ ↓ → "Suff" <suff beotel.yu> writes:
Actually it compiles on another compiler... removing -A and puting -Jm in
DMC doesn't change the outcome.
Please note that function template is specialised with T=void* while
compiler is requiring explicit cast from T to void*
i am not sure what ansi says about value template parameters in form of a
function pointer, however if that is allowed by standard then this is a
compiler bug, i am not looking for workaround just reporting bug if it's not
already known.
Anyway, thanks for your reply.

Suff

"Matt Morgan" <geckofood yahoo.com> wrote in message
news:cfei0t$1f87$1 digitaldaemon.com...
 Try checking "Relax Type Checking" in the project compiler settings tab
 (GUI) or use the -Jm option (cmdline).

 "DigitalMars" <suff beotel.yu> wrote in message
 news:cfbpqo$15eb$1 digitaldaemon.com...
 greetings...

 following does not compile... (scppn 8.40.2n)

 template<typename T,T (*Init)()> T tmpl()
 {
     static T mT(Init());
     return mT;
 };

 void* func()
 {
     return 0;
 };

 int main()
 {
     void* X=tmpl<void*,func>();
     return 0;
 };

 gives:
 void* X=tmpl<void*,func>();
                          ^
 equinoxtest.cpp(14) : Error: need explicit cast to convert
 from: void *(*C func)()
 to  : T(*C func)()
 equinoxtest.cpp(5) : Error: need explicit cast to convert
 from: T
 to  : void *
 void* X=tmpl<void*,func>();
                          ^
 equinoxtest.cpp(14) : Error: need explicit cast to convert
 from: void *(*C func)()
 to  : T(*C func)()
 --- errorlevel 1

 not sure if this is known issue and if this actually is valid ansi code


 not

 Suff


Aug 12 2004