You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
:15:5: error: static_assert failed "Variable too large #1"
static_assert(CHECK_NUM(s.val), "Variable too large #​1"); // Should not fail here
^ ~~~~~~~~~~~~~~~~
/usr/include/assert.h:143:24: note: expanded from macro 'static_assert'
define static_assert _Static_assert
^
1 error generated.
Compiler returned: 1
Based on the C11 standard section 6.3.1.1 Boolean, characters and integers :
If an int can represent all values of the original type (as restricted by the width, for a bit-field), the value is converted to an int; otherwise, it is converted to an unsigned int. These are called the integer promotions.) All other types are unchanged by the integer promotions.
I would expect _Generic((s.val), ...) to return 1 for int in this case.
The text was updated successfully, but these errors were encountered:
Extended Description
Here is the reproduction of the bug: https://godbolt.org/z/_IWIqC
The compilation fails on the static_assert, while it shouldn't based on the C11 standard (see quoting below in this post).
The code example below was compiled with the following options: -O3 -std=c11 -Wall -Wextra -v
#include <stdint.h>
#include <assert.h>
#define CHECK_NUM(num) _Generic((num),
uint64_t : 0,
int64_t : 0,
default : 1)
int main(void)
{
struct _s
{
uint64_t val : 1;
} s = {0};
}
The compilation output:
clang version 9.0.0 (tags/RELEASE_900/final 372344)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-9.0.0/bin
Found candidate GCC installation: /opt/compiler-explorer/gcc-9.2.0/lib/gcc/x86_64-linux-gnu/9.2.0
Selected GCC installation: /opt/compiler-explorer/gcc-9.2.0/lib/gcc/x86_64-linux-gnu/9.2.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@MX32
Selected multilib: .;@m64
"/opt/compiler-explorer/clang-9.0.0/bin/clang-9" -cc1 -triple x86_64-unknown-linux-gnu -S -disable-free -disable-llvm-verifier -discard-value-names -main-file-name example.c -mrelocation-model static -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -momit-leaf-frame-pointer -v -coverage-notes-file /home/ubuntu/./output.gcno -resource-dir /opt/compiler-explorer/clang-9.0.0/lib/clang/9.0.0 -internal-isystem /usr/local/include -internal-isystem /opt/compiler-explorer/clang-9.0.0/lib/clang/9.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wall -Wextra -std=c11 -fdebug-compilation-dir /home/ubuntu -ferror-limit 19 -fmessage-length 0 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -mllvm --x86-asm-syntax=intel -faddrsig -o ./output.s -x c
clang -cc1 version 9.0.0 based upon LLVM 9.0.0 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/opt/compiler-explorer/clang-9.0.0/lib/clang/9.0.0/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
/usr/include/assert.h:143:24: note: expanded from macro 'static_assert'
define static_assert _Static_assert
1 error generated.
Compiler returned: 1
Based on the C11 standard section 6.3.1.1 Boolean, characters and integers :
If an int can represent all values of the original type (as restricted by the width, for a bit-field), the value is converted to an int; otherwise, it is converted to an unsigned int. These are called the integer promotions.) All other types are unchanged by the integer promotions.
I would expect _Generic((s.val), ...) to return 1 for int in this case.
The text was updated successfully, but these errors were encountered: