<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/78531>78531</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang]compile fail when declare the snprintf function
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dongjianqiang2
</td>
</tr>
</table>
<pre>
cat test.c:
`#include <stdio.h>
int snprintf(char* s, size_t n, const char* format, ...);
int main()
{
char buffer[50];
char* s = "runoobcom";
int j = snprintf(buffer, 6, "%s\n", s);
printf("string:\n%s\ncharacter count = %d\n", buffer, j);
return 0;
}`
clang test.c -c -o test.o -D_FORTIFY_SOURCE=2 -O2
<source>:3:5: error: expected parameter declarator
3 | int snprintf(char* s, size_t n, const char* format, ...);
| ^
![image](https://github.com/llvm/llvm-project/assets/98140180/edf03272-650d-4bd8-8e69-555fe7c9437a)
Refer to https://godbolt.org/z/3xnbe6E9M
After analysis, I find that this is caused by inconsistent declaration of the __va_arg_pack macro in glibc
https://github.com/bminor/glibc/blob/9ea3686266dca3f004ba874745a4087a89682617/libio/bits/stdio2.h#L62C9-L62C22
This difference is due to the default __GNUC__ macro in clang.
https://github.com/bminor/glibc/blob/9ea3686266dca3f004ba874745a4087a89682617/misc/sys/cdefs.h#L361C1-L361C1
`clang -dM -E - < /dev/null |grep GNUC
#define __GNUC_MINOR__ 2
#define __GNUC_PATCHLEVEL__ 1
#define __GNUC_STDC_INLINE__ 1
#define __GNUC__ 4
`
Do we have any plans to update this version of __GNUC__ in clang?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VVtv4zYT_TX0y0CGRIq6PPjBka3vC5BLkc0W6JNAkSObqUy6JJXd7K8vKF8SBNgFChT1g0SLnMs5c2YovNc7g7gi_IbwzUJMYW_dSlmze9HC_KWF2dFFb9XbSooAAX1YSsLWJN2QdE2KlFCmjRwnhUBY44PS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