[llvm-bugs] [Bug 48407] New: Consider forbidding non-constant expressions in offsetof

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Dec 6 02:18:21 PST 2020


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

            Bug ID: 48407
           Summary: Consider forbidding non-constant expressions in
                    offsetof
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: slyfox at inbox.ru
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

gcc-11 will deliberately become stricter and will disallow non-constant
expressions in offsetof: https://gcc.gnu.org/PR95942

Complete example:

  // $ cat.bug.cc
  struct a {
    int b;
    char c[100];
  };
  unsigned long d(long e) { return __builtin_offsetof(a, c[e]); }

$ g++-11.0.0 -c bug.cc -o bug.o
bug.cc: In function 'long unsigned int d(long int)':
bug.cc:6:60: error: 'e' is not a constant expression
    6 |   unsigned long d(long e) { return __builtin_offsetof(a, c[e]); }
      |                                                            ^
$  clang++-11 -c bug.cc -o bug.o
<ok>

Should clang also reject the code above? If not should clang emit warning on
-Wall that non-standard extension is being used?

Thank you!

-- 
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/20201206/65965fcb/attachment.html>


More information about the llvm-bugs mailing list