return 类型中的不完整类型和声明但未定义的函数的参数

Incomplete types in return-type and parameters of a function declared but not defined

以下代码是否有效? (godbolt)

typedef struct none none;
none f(none, none);

要明确:标识符 f 从未出现在翻译单元中 再次并且函数本身从未被定义,甚至在另一个 翻译单元。

C17 标准明确表示允许参数具有不完整的类型:

(6.7.6.3 (12)) If the function declarator is not part of a definition of that function, parameters may have incomplete type and may use the [*] notation in their sequences of declarator specifiers to specify variable length array types.

因此 cparser 在此基础上拒绝代码是错误的。

至于return种,似乎都没有明确的说法。 cppreference 说“函数的 return 类型 [...] 必须是 complete 非数组对象类型或 void 类型”,但我不能在标准中找不到相应的要求。该标准在“函数定义”下的 6.9.1 (3) 中确实说“函数的 return 类型应为 void 或数组类型以外的完整对象类型”,但我读到仅指定义。同样,6.5.2.2(1) 要求被调用的函数必须具有完整的 return 类型或 void.

所以我的意见是不完整的 return 类型在声明中是允许的,只要函数没有被定义或调用。但很难确定。