From reading the standard I was unable to figure out if the following code violates ODR:
// a.h
#ifndef A_HEADER_FILE
#define A_HEADER_FILE
namespace {
int v;
}
inline int get_v() { return v; }
#endif // A_HEADER_FILE
// a.cpp
#include "a.h"
void f() {
int i = get_v();
// ...
}
// b.cpp
#include "a.h"
void g() {
int i = get_v();
// ...
}
Supposedly, get_v()
references different variables in each translation unit so it violates ODR
.
This answer: Inline functions and external linkage says that inline relaxes ODR
so I am not sure why this is still an error?
Can someone link me to where in the standard it is specified if this is an ODR
violation or not?