草庐IT

c-linkage

全部标签

C++ block scope extern declaration linkage,混淆C++标准解释

标准N3242(C++11草案)和N3797(C++14draft)两者有相同的段落。§3.5Programandlinkage[basic.link]¶6Thenameofafunctiondeclaredinblockscopeandthenameofavariabledeclaredbyablockscopeexterndeclarationhavelinkage.Ifthereisavisibledeclarationofanentitywithlinkagehavingthesamenameandtype,ignoringentitiesdeclaredoutsidethei

c++ - 铿锵错误 : non-type template argument refers to function that does not have linkage -- bug?

我有一些非常简单的(C++11)代码,最新的clang(version3.4trunk187493)无法编译,但GCC编译正常。代码(下面)实例化函数模板foo使用局部函数类型Bar然后尝试将其地址用作类模板Func的非类型模板参数:templatestructFunc{};templateexterninlinevoidfoo(){usingFoo=Func>;}intmain(){structBar{};//function-localtypefoo();return0;}clang发出以下错误:error:non-typetemplateargumentreferstofunct

C++ 标准 : do namespace-scoped constexpr variables have internal linkage?

假设我们有一个标题foo.h包含以下内容:#ifndefFOO_H_#defineFOO_H_namespacefoo{constexprstd::string_viewkSomeString="blah";}#endif//FOO_H_foo::kSomeString是否保证在包含foo.h的任何翻译单元中具有内部链接?这在C++11和C++17之间是否有所不同?在标准草案中[basic.link]/3说Anamehavingnamespacescopehasinternallinkageifitisthenameof[...]anon-inlinevariableofnon-vol
12