#3185·Catch2

使宏尽可能符合 constexpr 规范

作者: hobezero创建于 2026年7月30日更新于 2026年8月25日
标签Feature Request

如果我实现了这个,我会添加一些接受标签类型的构造函数:

cpp
struct ConstexprInit {
	explicit
	ConstexprInit() = default;
};

class ScopedMessage {
public:
	constexpr ScopedMessage(ConstexprInit) {}
	explicit ScopedMessage(MessageBuilder&& builder);
	ScopedMessage(ScopedMessage& duplicate) = delete;
	ScopedMessage(ScopedMessage&& old) noexcept;
	CATCH_INTERNAL_CONSTEXPR_DTOR ~ScopedMessage() {
#if CATCH_INTERNAL_HAS_IF_CONSTEVAL
		if (!consteval) {
#elif CATCH_INTERNAL_HAS_IS_CONSTANT_EVALUATED
		if (!std::is_constant_evaluated()) {
#endif
			destroyImpl();
#if CATCH_INTERNAL_HAS_IF_CONSTEVAL || CATCH_INTERNAL_HAS_IS_CONSTANT_EVALUATED
		}
#endif
	}

	MessageInfo m_info;
	bool m_moved = false;
};

内容来源: catchorg/Catch2