c++modulec++20inlinelinkage

Usage of exported inline variables in c++20 modules


Is there any use of exported inline variables in c++20 modules?

Is there any difference between

export constexpr auto val1 = 0;
export const auto val2 = 0;
export auto val3 = 0;

and

export inline constexpr auto val1 = 0;
export inline const auto val2 = 0;
export inline auto val3 = 0;

If so, what's the difference? And are there reasonable use cases for one or the other? Can there be an ODR violation using modules?


Solution

  • inline doesn't have any special meaning with regard to C++ modules.

    Two modules (or one module and the global fragment) cannot export the same entity, regardless of whether it's a variable or something else. To do so is not an ODR violation, but it is ill-formed, with no diagnostic required in most cases.