Home > Software engineering >  undefined reference issue with latest gcc
undefined reference issue with latest gcc

Time:06-07

I have link-time error when trying to compile following code with gcc 12.1.0. With clang, msvc and older gcc it compiles as expected.

template<typename T>
void def()
{}

template<void (*foobar)() = def<int>>
void bar()
{
    foobar();
}

template<typename T>
void foo()
{
    bar();
}

int main()
{
    foo<int>();
}
Error: /usr/bin/ld: /tmp/cchkaKVw.o: in function `void bar<&(void def<int>())>()':
> main.cpp:(.text._Z3barIXadL_Z3defIiEvvEEEvv[_Z3barIXadL_Z3defIiEvvEEEvv] 0x5): undefined reference to `void def<int>()'

Is this a gcc regression or is there some problem with this code?

CodePudding user response:

Reported this bug to GCC Bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105848

  • Related