[英]What is the purpose of the bullet points in [basic.link]/8 in N4140? They don't seem to bring anything new the statement preceding them
[英]Is my understanding about [basic.link]/7 in N4140 correct?
VS2015编译并执行以下代码段没有问题。 g ++和clang没有链接代码,我认为它们是正确的。
#include <iostream>
namespace X {
void p() {
void q(); // This is a block scope declaration of the function q() with external
// linkage (by §3.5/6), which then must be defined in namespace X,
// according to §3.5/7, and not in the global namespace.
q();
}
}
void q() { std::cout << "q()" << '\n'; }
int main()
{
X::p();
}
您的示例几乎与[basic.link] / 7中的示例相同 - 是的,您的解释是正确的。
使用未定义的函数q
会导致程序格式错误的NDR 。 因此VC ++在技术上符合要求。 但是,你肯定想报告它。
注意VC ++如何生成相同的输出 (“q()”),即使我们添加q
的内部定义:
namespace X {
void p() {
void q();
q();
}
void q() { std::cout << "This would be right"; }
}
void q() { std::cout << "q()" << '\n'; }
......但在使用extern
时确实有明智的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.