Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22285

Class template static field initialization different results on GCC and Clang

$
0
0

Consider the following C++ code example:

#include<iostream>class B {public:    int val;    B(int v):val(v){        std::cout<< val << "\n";    }};template<typename T>class A {public:    static B b;};template<typename T>B A<T>::b = B(1);int main() {    A<int>::b.val;    return 0;}

On GCC 11.4.0, build with g++ main.cc -g got output 1.

On Clang 14.0.0, build with clang++ main.cc -g got segfault.

Ubuntu 22.04.4 LTS

Cannot understand the reason of such behavior, would be very grateful for any help.


Viewing all articles
Browse latest Browse all 22285

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>