Clang,这些类型如何冲突?

Clang, how do these types conflict?

尝试用 clang 编译 Python 解释器(在 Windows 上),我得到(经过一些改进后):

c:\Python-3.10.4\Python\pytime.c:603:5: error: conflicting types for '_PyTime_AsTimeval'
int _PyTime_AsTimeval(_PyTime_t t, struct timeval *tv, _PyTime_round_t round)
    ^
C:\Python-3.10.4\Include/cpython/pytime.h:126:5: note: previous declaration is here
int _PyTime_AsTimeval(_PyTime_t t, struct timeval *tv, _PyTime_round_t round);
    ^

嗯...我觉得这些并不矛盾!我错过了什么? Python 代码是否对这些声明做了一些不寻常的事情?有没有办法让 clang 提供有关它看到的冲突的更多信息? (Microsoft 编译器毫无怨言地接受了此代码。)

找到了!问题是 struct timeval 在读取函数声明时尚未声明。 Microsoft C 将其视为 'global declaration of the struct will be forthcoming' 的含义; clang 将其视为 'make a temporary declaration, then discard it, so that the function prototype is incompatible with later definition'.

void square(struct foo *f);

struct foo {
  int x;
};

void square(struct foo *f) {}

并且可以在 pytime.h 中进行修补,方法是在函数原型之前插入:

struct timeval;

我不知道这两种行为是否更符合标准的措辞,但无论如何都将其报告为 clang 中的错误,理论上与 Microsoft 编译器的行为方式相同更有用的行为。