Violating the one definition rule by simply linking dynamically
问题 Question: Are dynamically linked C++ programs on ELF platforms always on the brink of producing undefined behavior by violating the one definition rule? More specific: By simply writing a shared library exposing one function #include <string> int __attribute__((visibility("default"))) combined_length(const char *s, const char *t) { const std::string t1(t); const std::string u(s + t1); return u.length(); } and compiling it with GCC 7.3.0 via $ g++ -Wall -g -fPIC -shared \ -fvisibility=hidden