[glibc/maskray/clang] linux: Fix a non-constant expression in _Static_assert
Fangrui Song
maskray@sourceware.org
Sun Oct 10 23:13:05 GMT 2021
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=87cb4df467880ac2b6e4f9878c8a2c0d3a2b28bb
commit 87cb4df467880ac2b6e4f9878c8a2c0d3a2b28bb
Author: Fangrui Song <maskray@google.com>
Date: Thu Oct 7 17:45:16 2021 -0700
linux: Fix a non-constant expression in _Static_assert
According to C11 6.6p6, `const int` as an operand may not make up a
constant expression. GCC -O0 errors:
../sysdeps/unix/sysv/linux/opendir.c:107:19: error: static_assert expression is not an integral constant expression
_Static_assert (allocation_size >= sizeof (struct dirent64),
-O2 -Wpedantic has a similar warning.
See https://gcc.gnu.org/PR102502 for GCC's inconsistency.
Use enum which is guaranteed to be a constant expression.
This also makes the file compilable with Clang.
Fixes: 4b962c9e859de23b461d61f860dbd3f21311e83a ("linux: Simplify opendir buffer allocation")
Diff:
---
sysdeps/unix/sysv/linux/opendir.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sysdeps/unix/sysv/linux/opendir.c b/sysdeps/unix/sysv/linux/opendir.c
index 48f254d169..88640f44ee 100644
--- a/sysdeps/unix/sysv/linux/opendir.c
+++ b/sysdeps/unix/sysv/linux/opendir.c
@@ -103,7 +103,7 @@ __alloc_dir (int fd, bool close_fd, int flags,
file system provides a bogus value. */
enum { max_buffer_size = 1048576 };
- const size_t allocation_size = 32768;
+ enum { allocation_size = 32768 };
_Static_assert (allocation_size >= sizeof (struct dirent64),
"allocation_size < sizeof (struct dirent64)");
More information about the Glibc-cvs
mailing list