Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 709
Martin Fehrs Avatar asked Oct 24 '25 14:10

Martin Fehrs


1 Answers

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.

like image 177
Nicol Bolas Avatar answered Oct 27 '25 03:10

Nicol Bolas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!