On Tue, Dec 12, 2023 at 3:05 PM Thiago Macieira via Std-Proposals <std-proposals@lists.isocpp.org> wrote:
On Tuesday, 12 December 2023 17:00:59 -03 Lénárd Szolnoki wrote:
> > constexpr are implicitly inline, so these two don't actually work
> > independently. At a minimum you must ensure that the former is
> > visible before
> > the latter. Or write extern constexpr.
>
> constexpr is not implicitly inline for namespace scope non-template
> variables.

Are you sure? This is an area that changed in C++14 or 17. I might be mis-
remembering the details, but something did change to make something implicitly
inline.

Const variables at namespace scope have always had implicit internal storage duration (a.k.a. "implicitly static"). In C++11 and later, this also includes `constexpr` variables because `constexpr` implies const. In C++17, inline variables were added as an exception to this rule: so if you don't declare it inline, then it's implicitly static, but if you do declare it inline, then it's just inline. In C++20, variables declared in modules are also an exception: http://eel.is/c++draft/basic.link#3.2.1

It's correct that you can avoid this either by having the non-defining declaration earlier in the TU or by putting `extern` on the definition.
 

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering



--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals


--
Brian Bi