I've picked up the habit to always enclose types defined in source files in unnamed namespaces because I know they can cause ODR violations:
// my_source.cpp
namespace {
struct MyStruct {};
}
What happens though in a source file that doesn't define a type, but merely aliases an existing one e.g.:
// another_source.cpp
using error_t = ::prj::telemetry::ErrorType;
could this create an ODR violation or cause weird linker behavior (e.g. discard one of the two types) if some other source contains:
// some_other_source.cpp
using errot_t = ::prj::linalg::ErrorType;
basically would the same rules applied to type definitions, also apply to typedefs?
A typedef or a using statement does not introduce a new type, it just introduces an alias to another type, so no ODR violation is possible. From cppreference:
typedef
using