g++ variadic template issue

后端 未结 1 1947
渐次进展
渐次进展 2021-01-11 19:51

So I gave this program to g++ and clang (both on Linux, x86_64):

#include 

using namespace std;

template
struct A {
  sta         


        
相关标签:
1条回答
  • 2021-01-11 20:12

    Your code is incorrect. The important part of the standard is 6.6.3/1 [basic.start.dynamic] in N4659:

    Dynamic initialization of a non-local variable with static storage duration is unordered if the variable is an implicitly or explicitly instantiated specialization [...]

    Because the initialization is not ordered, you cannot rely on the order of destruction. Any order is legal, regardless of order of construction. See 6.6.4/3 [basic.start.term]

    gcc is thus allowed to destroy s before it destroys a, which is what happens and causes the weird output. Live.

    0 讨论(0)
提交回复
热议问题