Should `const` and `constexpr` variables in headers be `inline` to prevent ODR violations? : <p>Consider the following header and assume it is used in several TUs:</p>

<pre><code>static int x = 0;

struct A {
    A() {
        ++x;
        printf("%d\n", x);
    }
};
</code></pre>

<p>As <a href="https://stackoverflow.com/questions/4276794/static-keyword-in-h-file-and-internal-linkage">this question</a> explains, this is an ODR violation and, therefore, UB.</p>

<p>Now, <a href="https://stackoverflow.com/questions/41133290/using-constants-in-header-file-with-odr-compliance">there is no ODR violation</a> if our <code>inline</code> function refers to a non-<code>volatile</code> <code>const</code> object and we do not odr-use it within that function (plus the other provisions), so this still works fine in a header:</p>

<pre><code>constexpr int x = 1;

struct A {
    A() {
        printf("%d\n", x);
    }
};
</code></pre>

<p>But if we do happen to odr-use it, we are back at square one with UB:</p>

<pre><code>constexpr int x = 1;

struct A {
    A() {
        printf("%p\n", &amp;x);
    }
};
</code></pre>

<p>Thus, given we have now <code>inline</code> variables, should not the guideline be to mark all <code>namespace</code>-scoped variables as <code>inline</code> in headers to avoid all problems?</p>

<pre><code>constexpr inline int x = 1;

struct A {
    A() {
        printf("%p\n", &amp;x);
    }
};
</code></pre>

<p>This also seems easier to teach, because we can simply say "<code>inline</code>-everything in headers" (i.e. both function and variable definitions), as well as "never <code>static</code> in headers".</p>

<p>Is this reasoning correct? If yes, are there any disadvantages whatsoever of always marking <code>const</code> and <code>constexpr</code> variables in headers as <code>inline</code>?</p>
