[cfe-commits] r113018 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/flexible-array-test.cpp

Francois Pichet pichet2000 at gmail.com
Mon Sep 6 21:49:40 PDT 2010


Any reason to to disallow flexible array element in union?
Both gcc 4.5 and msvc allow it. For example:
struct A
{
    int   Length;
    union
    {
        char   dataC[];
        short  dataS[];
        long   dataL[];
    };
};

You see code like that in MSVC headers file. I was planning to submit
a patch this week to allow such code.

On Fri, Sep 3, 2010 at 5:53 PM, Anders Carlsson <andersca at mac.com> wrote:
> Author: andersca
> Date: Fri Sep  3 16:53:49 2010
> New Revision: 113018
>
> URL: http://llvm.org/viewvc/llvm-project?rev=113018&view=rev
> Log:
> It's OK for classes to have flexible array elements (but not unions).
>
> Modified:
>    cfe/trunk/lib/Sema/SemaDecl.cpp
>    cfe/trunk/test/SemaCXX/flexible-array-test.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=113018&r1=113017&r2=113018&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Sep  3 16:53:49 2010
> @@ -6564,7 +6564,7 @@
>       EnclosingDecl->setInvalidDecl();
>       continue;
>     } else if (FDTy->isIncompleteArrayType() && i == NumFields - 1 &&
> -               Record && Record->isStruct()) {
> +               Record && !Record->isUnion()) {
>       // Flexible array member.
>       if (NumNamedMembers < 1) {
>         Diag(FD->getLocation(), diag::err_flexible_array_empty_struct)
>
> Modified: cfe/trunk/test/SemaCXX/flexible-array-test.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/flexible-array-test.cpp?rev=113018&r1=113017&r2=113018&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/flexible-array-test.cpp (original)
> +++ cfe/trunk/test/SemaCXX/flexible-array-test.cpp Fri Sep  3 16:53:49 2010
> @@ -43,3 +43,13 @@
>    int blah;
>    S strings[];        // expected-error {{flexible array member 'strings' of non-POD element type 'S []'}}
>  };
> +
> +class A {
> +  int s;
> +  char c[];
> +};
> +
> +union B {
> +  int s;
> +  char c[]; // expected-error {{field has incomplete type 'char []'}}
> +};
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>




More information about the cfe-commits mailing list