specialized templates not working as expected

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi list,

I have the following code,
which compiles with MSVC 19.14 (godbolt.org),
but DOESN'T on a recent g++ (see below).

Am I missing something here?
Activating the marked block makes it compilable for g++.

I understand that this is a template instantiation problem.
But I'm wondering why there is such a difference
in standard interpretation for such an old C++ feature.

I also understand that there are other possibilities
to achieve a similar effect, but I don't like to discuss
these possibilities here.

Kind Regards Andre

//////////////////////////
//// begin of testspec.h
template<class T>
class A
{
public:
    A();
    void foo1();
    void foo2();
    void foo3();
};

typedef A<int> Aint;
//// end of testspec.h

//// begin of testspec.cpp
//#include "testspec.h"

#include <iostream>

#if 0
/////////////// can this block be simplified or even removed? //////////
template<>
void
A<int>::foo1();

template<>
void
A<int>::foo2();

template<>
void
A<int>::foo3();
/////////////// can this block be simplified or even removed? //////////
#endif

template<>
A<int>::A()
{
    foo1();
    foo2();
    foo3();
    std::cout << "hello world" << std::endl;
}

template<>
void
A<int>::foo1()
{
    std::cout << "foo1" << std::endl;
}

template<>
void
A<int>::foo2()
{
    std::cout << "foo2" << std::endl;
}

template<>
void
A<int>::foo3()
{
    std::cout << "foo3" << std::endl;
}
//// end of testspec.cpp

//// begin of main.cpp
//#include "testspec.h"

int main()
{
    Aint a;
    return 0;
};
// end of main.cpp
//////////////////////////



//////////////////////////
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --with-linker-hash-style=gnu
--enable-plugin --enable-initfini-array --with-isl
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-gnu-indirect-function --enable-cet --with-tune=generic
--with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 9.2.1 20190827 (Red Hat 9.2.1-1) (GCC)
//////////////////////////




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux