- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
C++ 20 draft [concept.default.init] 没有精确定义 default_initializable
template<class T>
concept default_initializable = constructible_from<T> &&
requires { T{}; } &&
is-default-initializable <T>; // exposition-only
For a type
T
, is-default-initializable <T> is true if and only if the variable definition
T t;
is well-formed for some invented variable t; otherwise it is false. Access checking is performed as if in a context unrelated to T. Only the validity of the immediate context of the variable initialization is considered.
template<class T>
concept default_initializable =
std::constructible_from<T> &&
requires { T{}; } &&
requires { ::new (static_cast<void*>(nullptr)) T; };
nullptr
调用的placement-new 运算符参数导致未定义的行为。
9) Called by the standard single-object placement new expression. The standard library implementation performs no action and returns ptr unmodified. The behavior is undefined if this function is called through a placement new expression and ptr is a null pointer.
T t;
必须是良构的吗?对我来说,这看起来很奇怪,因为简单需求和复合需求都没有提供 require
T t;
的可能性。正是。但为什么这样做呢?
最佳答案
指定时,未定义的行为是评估的结果 [expr.new]/20
If the allocation function is a non-allocating form ([new.delete.placement]) that returns null, the behavior is undefined.
Expressions appearing within a requirement-body are unevaluated operands.
An unevaluated operand is not evaluated.
decltype( std::declval<int&>() + std::declval <int&> ())
也会是UB。
关于c++ - UB 在未评估的上下文中(例如需要表达式)仍然是 UB 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62000436/
我是一名优秀的程序员,十分优秀!