我对N4140中[basic.link]/7的理解正确吗
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
时确实具有可感知的行为。
相关文章:
- 如何在Visual Basic中使用矩形函数OpenGL绘制矩形
- 这是 basic.def.odr 部分的缺陷吗?
- 未定义的对象(〔basic.life〕/8):为什么允许引用重新绑定(和常量修改)
- C++标准在[basic.scope.hiding]中"same scope"到底意味着什么?
- 为什么我们需要 [basic.scope.class]/2?
- [basic.lookup]/1 中最后一句话是什么意思?
- 字符串C :libc abi.dylib:终止未被发现的类型std :: out_of_range:basic
- TagniFi的HTTPS Basic Authentication 在 Qt 中失败
- 尝试实施 PIMPL idom 时如何避免"redefinition; different basic types"
- 这个给定算法中的"basic operation"究竟是什么
- 我在理解 [basic.scope.pdecl]/7 时遇到一些困难
- 根据 [basic.def.odr]/2,'A::a[0]' 的潜在结果集为空.为什么它是空的?
- 我的C 程序在CodeBlocks中提供了正确的结果,但在Visual Basic 2005 Express Edi
- [basic.lookup.unqual]/3 中的第一个示例
- 将音乐的子字符串从 BASIC 转换为 C++
- 使用 Visual Basic 更改C++中的"Press any key to Continue..."
- 从无操纵项目(C/C VS2005)调用托管代码(C#/Visual Basic VS2010)
- 试图理解C++14中的[basic.def.odr]/2(N4140)
- N4140 中 [basic.link]/8 中的要点的目的是什么?他们似乎没有带来任何新的东西 他们之前的声明
- 我对N4140中[basic.link]/7的理解正确吗