C++ 将函数标记为 experimental/not 完全实现

C++ mark a function as experimental/not fully implemented

我有一个功能,由于各种原因我需要部分实现,我想防止未来的用户(将来当我忘记我这样做的时候读我)知道这个功能是不完整的,越野车和未经测试。

选项 n1 只是添加评论 // Warning this thing is partially implemented and will break randomly 然而,这不会创建编译时警告,所以我不是粉丝。

选项 n2 是使用 [[deprecated("reason")]],它具有引发编译警告的优点,但它具有误导性,该功能并未被弃用,它实际上与弃用相反,它是一个 WIP,也许有一天会完全已实施。

有其他选择吗?

[[deprecated]] 属性正是它的用途(强调我的):

https://en.cppreference.com/w/cpp/language/attributes

[deprecated]

[deprecated("reason")]

indicates that the use of the name or entity declared with this attribute is allowed, but discouraged for some reason

您仍然可以使用该功能,只是收到一条警告消息,提示您不应依赖它的使用。

警告:MSVC 违反标准并发出编译器 错误(由于 SDL 标志默认打开)而不是警告。

标准 C++ 中唯一的东西是 [[deprecated("message")]] 属性。

GNU 有 non-standard Function Attribute 用于 warning 消息:

warning ("message")
If this attribute is used on a function declaration and a call to such a function is not eliminated through dead code elimination or other optimizations, a warning which will include message will be diagnosed. This is useful for compile time checking, especially together with __builtin_constant_p and inline functions. While it is possible to define the function with a message in .gnu.warning* section, when using this attribute the problem will be diagnosed earlier and with exact location of the call even in presence of inline functions or when not emitting debugging information.