[LLVMbugs] [Bug 13882] New: Clang should not accept initializer lists that cause arrays to have zero length

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Sep 19 16:00:24 PDT 2012


             Bug #: 13882
           Summary: Clang should not accept initializer lists that cause
                    arrays to have zero length
           Product: clang
           Version: 3.1
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: kyle at omnigroup.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 9238
  --> http://llvm.org/bugs/attachment.cgi?id=9238
Test case showing incorrect creation of zero-length array via initializer lists

Related to #13881 (which deals with explicitly declaring an array with a
zero-valued constant integer expression), but the standard is ambiguous here:

Clang accepts the attached code, which uses an initializer list to define the
length of an array of otherwise unknown size, and uses a compound literal to
declare an array of zero length.

I believe both of these constructs should be illegal, even though the standard
doesn't come right out and say it. §6.7.8 ¶22 says:

"""If an array of unknown size is initialized, its size is determined by the
largest indexed element with an explicit initializer. At the end of its
initializer list, the array no longer has incomplete type."""

And the definition of compound literals at § defers to initializer lists
for length semantics.

Since zero-length arrays are generally understood to be invalid outside of
flexible array members, I believe it should be illegal to create a zero-length
array by means of an initializer list.

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list