The issue was that the code generated by AC_LANG_PROGRAM
produces warnings, and hence -Werror makes detection fail:
$ gcc -x c -Werror -Wstrict-prototypes - <<<'int main() {}'; echo $?
<stdin>:1:5: error: function declaration isn’t a prototype [-Werror=strict-prototypes]
cc1: all warnings being treated as errors
1