[llvm-bugs] [Bug 44855] New: Combining a pointer to array of const TYPE with an otherwise size-compatible array of TYPE should work and yield only a _pedantic_ warning

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Feb 9 05:37:24 PST 2020


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

            Bug ID: 44855
           Summary: Combining a pointer to array of const TYPE with an
                    otherwise size-compatible array of TYPE should work
                    and yield only a _pedantic_ warning
           Product: clang
           Version: 9.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C
          Assignee: unassignedclangbugs at nondot.org
          Reporter: pskocik at gmail.com
                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

C++ allows e.g.,  combining (int const(*)[100])x with (int (*)[100])y as in 

 0? (int(*)[100])0 : (int const(*)[100])0

yielding an expression of type int const(*)[100].

The C standard technically disallows this (could be considered a defect in the
standard) but this  kind of combining/conversion is completely harmless and so
GCC only warns about it under -pedantic.

Consequently, under GCC, it is possible to disable these warnings by enclosing
the "offending" code snippets in (__extension__({ ;}).

This doesn't work on clang, because the above elicits a full (rather than just
a pedantic) warning on clang.

Furthermore, the combined type on clang is void* rather than int(*)[100].

The gcc behavior is more useful.

Some examples with comments at: https://gcc.godbolt.org/z/e7sXdB

-- 
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/20200209/7dac8b0d/attachment.html>


More information about the llvm-bugs mailing list