3 ms·
Right, the inline keyword in C++ is mainly used to dodge ODR. When you really care about inlining, you want an attribute like always_inline, which emits an erro
by ridiculous_fish 5y ago
Right, the inline keyword in C++ is mainly used to dodge ODR. When you really care about inlining, you want an attribute like always_inline, which emits an error if the function cannot be inlined (e.g. is recursive).
- varajelle 5y agoLittle to do with ODR. The inline function must have the same tokens in every translation unit otherwise it is undefined behaviour.
- dataflow 5y agoSame tokens? So you're saying 'inline int foo(void);' + 'typedef int I; inline I foo(void);' is UB?
- MauranKilom 5y agoQuoting the C++ 17 standard draft [0]: > There can be more than one definition in a program of [...an] inline function [...] as long as all of the following is true: > - each definition consists of the same sequence of tokens (typically, appears in the same header file) > [...] > If all these requirements are satisfied, the program behaves as if there is only one definition in the entire program. Otherwise, the program is ill-formed, no diagnostic required. [0]: https://timsong-cpp.github.io/cppwp/n4659/basic.def.odr#6.1 https://timsong-cpp.github.io/cppwp/n4659/basic.def.odr#6.1