https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97771
--- Comment #7 from Erez Strauss <erstrauss at gmail dot com> --- Hi Andrew, Here is a very simple test program, under clang++ its output is 3, as expected. Its output is 2 in case of g++ 11.2.1 20210728 (Red Hat 11.2.1-1) #include <iostream> static int X; typedef void (*funcP)(); static funcP g_init_func [[gnu::used, gnu::section(".init_array")]] { []()->void{++X;} }; void funcA() { static funcP init_func [[gnu::used, gnu::section(".init_array")]] { []()->void{++X;} }; } template<typename T> void funcB() { static funcP init_func [[gnu::used, gnu::section(".init_array")]] { []()->void{++X;} }; } void testT() { funcB<int>(); } int main() { std::cout << X << std::endl; testT(); return 0; } Please test the above to generate 3 as output with g++. Thanks, Erez