Imagine we have a header foo.h
containing the following:
#ifndef FOO_H_
#define FOO_H_
namespace foo {
constexpr std::string_view kSomeString = "blah";
}
#endif // FOO_H_
Is foo::kSomeString
guaranteed to have internal linkage in any translation unit that includes foo.h
? Does this vary between C++11 and C++17?
In the draft standard [basic.link]/3 says
A name having namespace scope has internal linkage if it is the name of [...] a non-inline variable of non-volatile const-qualified type that is neither explicitly declared extern nor previously declared to have external linkage [...]
But I don't know if constexpr
counts as "const-qualified". Does the standard say so somewhere?
Assuming this is guaranteed to have internal linkage, it seems like there can be no problem with the ODR for this usage, right? (In contrast to what it says in this answer.)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…