1) Not overload inline keyword for ODR purposes
2) Emit a helpful message when an inline request cannot be fulfilled so developers understand compiler’s rationale.
So what exactly would inline (or implicit inline within a class) do, then? And how would you request relaxing ODR if it's not inline?
In an ideal world, I'd expect ODR violations only when there are two or more distinct definitions for a function. In other words, if src.cpp includes a.h and b.h and they both have a definition for foo(), then there is a true problem. If I have src1.cpp and src2.cpp and they both include a.h, I wish there was an intelligent mechanism to determine that only a single definition of foo exists.
I realize this is easier said than done since the compiler only deals with a single compilation unit at a time. But, strictly speaking, there is no programmer error here, there is only one definition of the function, but because of the way inner machinery of the language works, the linker sees multiple definitions of the same function.
Since the burden is on the programmer to resolve this, I'd have preferred a less confusing resolution than overloading the use of inline keyword. I'd have preferred inline do it's original job and have a separate keyword for marking functions that have a single definition.
I'd think the warning should be opt-in rather than opt-out; otherwise it likely would get too noisy.
Agreed.
BTW: do you prefer the way inline is implemented in C instead?
Haven't programmed in C since my college days :) It's not clear to me how this is better than C++. Again, for me, overloading the inline keyword to control enforcement of one-definition rule seems complicated. I'd have preferred a separate keyword.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
So what would you have the compiler do instead?
1) Not overload inline keyword for ODR purposes
2) Emit a helpful message when an inline request cannot be fulfilled so developers understand compiler’s rationale.
So what exactly would
inline
(or implicitinline
within a class) do, then? And how would you request relaxing ODR if it's notinline
?I'd think the warning should be opt-in rather than opt-out; otherwise it likely would get too noisy.
BTW: do you prefer the way
inline
is implemented in C instead?In an ideal world, I'd expect ODR violations only when there are two or more distinct definitions for a function. In other words, if
src.cpp
includesa.h
andb.h
and they both have a definition forfoo()
, then there is a true problem. If I havesrc1.cpp
andsrc2.cpp
and they both includea.h
, I wish there was an intelligent mechanism to determine that only a single definition offoo
exists.I realize this is easier said than done since the compiler only deals with a single compilation unit at a time. But, strictly speaking, there is no programmer error here, there is only one definition of the function, but because of the way inner machinery of the language works, the linker sees multiple definitions of the same function.
Since the burden is on the programmer to resolve this, I'd have preferred a less confusing resolution than overloading the use of
inline
keyword. I'd have preferredinline
do it's original job and have a separate keyword for marking functions that have a single definition.Agreed.
Haven't programmed in C since my college days :) It's not clear to me how this is better than C++. Again, for me, overloading the inline keyword to control enforcement of one-definition rule seems complicated. I'd have preferred a separate keyword.