[llvm-bugs] [Bug 48745] New: error: initializer element is not a compile-time constant for valid code

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jan 13 15:48:10 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=48745

            Bug ID: 48745
           Summary: error: initializer element is not a compile-time
                    constant for valid code
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jstenglein at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

For the following code:
struct wss {
  unsigned int  count;
  unsigned char _have_ct  : 1  ;
};
struct capab {
  struct wss _wss;
  unsigned char _have_type;
};
struct node {
  struct capab _capab;
};
struct node nd = {
    ._capab = {
      ._have_type = 1,
    },
    ._capab._wss.count = 1, // ERROR!
};

Clang gives error:
clang -emit-llvm test.c -c
error: initializer element is not a compile-time constant
1 error generated.

Code appears to be valid according to struct initialization rules, and gcc
gives no error:
gcc -c test.c
<No error>

Also, error message doesn't show error location in the code.

Versions:
clang --version
clang version 12.0.0 (https://github.com/llvm/llvm-project
f4f158b2f89e16ee7068d6292d2d46457d6932bb)
Target: x86_64-unknown-linux-gnu
Thread model: posix
gcc --version
gcc (GCC) 8.3.1 20190507 (Red Hat 8.3.1-4)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210113/45734c5d/attachment.html>


More information about the llvm-bugs mailing list