Does the one-definition-rule force a single static function variable to be created?

Viewed 731

As an example, consider this header:

#include <iostream>

template<bool = true>
struct A {
    A() {
        static int x;
        std::cout << &x << "\n";
    }
};

static A<> a;

What if I had two different C++ files including this file - would it print the same address twice, guaranteed? Even more importantly, if x was an object of a different type with a non-trivial constructor, would it be guaranteed to only be run once?

1 Answers
Related