[llvm-bugs] [Bug 49581] New: Missing -Wgnu-folding-constant for initialisers

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Mar 13 12:42:53 PST 2021


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

            Bug ID: 49581
           Summary: Missing -Wgnu-folding-constant for initialisers
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C
          Assignee: unassignedclangbugs at nondot.org
          Reporter: harald at gigawatt.nl
                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

clang has a -Wgnu-folding-constant warning for cases where the standard
requires a constant expression, the provided expression can be folded to a
constant, but this expression is not a constant according to the rules of the
standard. For instance, in C:

  const int a = 1;
  struct S { int b : a; };

results in

  warning: expression is not an integer constant expression; folding it to a
constant is a GNU extension [-Wgnu-folding-constant]
  struct S { int b : a; };
                     ^

This warning is missing for initialisers:

  const int a = 1;
  const int b = a; // invalid but not diagnosed

As neither GCC nor clang currently diagnoses this (also , but other compilers
issue an error message, this makes it very easy to accidentally write
non-portable code that does not get noticed until a user uses one of those
other compilers.

P.S.: The C standard does not require a diagnostic for this, so this is not a
conformance issue.

P.P.S.: Although the warning for the first example talks about this as a GNU
extension, I cannot find any version of GCC that allows the first example here,
it seems to be only clang that allows this. It may be good to reword the
warning at the same time.

-- 
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/20210313/698e00a6/attachment.html>


More information about the llvm-bugs mailing list