ODR violation via overload resolution
suggest changeEven with identical tokens for inline functions, the one-definition rule can be violated if lookup of a name doesn’t refer to the same entity. Let’s consider func in the following files:
- header.h
void overloaded(int);
inline void func() { overloaded('*'); }
- foo.cpp
#include "header.h"
void foo()
{
func(); // `overloaded` refers to `void overloaded(int)`
}
- bar.cpp
void overloaded(char); // can come from other include
#include "header.h"
void bar()
{
func(); // `overloaded` refers to `void overloaded(char)`
}
We have an ODR violation as overloaded refers to different entities depending on the translation unit. The program is ill-formed, and the implementation is not required to diagnose it.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents