[cfe-commits] r171783 - in /cfe/trunk: lib/Sema/SemaType.cpp test/SemaCXX/c99-variable-length-array-cxx11.cpp

Richard Smith richard at metafoo.co.uk
Mon Jan 7 14:38:58 PST 2013


On Mon, Jan 7, 2013 at 12:03 PM, Douglas Gregor <dgregor at apple.com> wrote:
> Author: dgregor
> Date: Mon Jan  7 14:03:16 2013
> New Revision: 171783
>
> URL: http://llvm.org/viewvc/llvm-project?rev=171783&view=rev
> Log:
> Use the C++11 POD definition in C++11 mode to determine whether one
> can create a VLA of class type. Fixes <rdar://problem/12151822>.
>
> Added:
>     cfe/trunk/test/SemaCXX/c99-variable-length-array-cxx11.cpp
> Modified:
>     cfe/trunk/lib/Sema/SemaType.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaType.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=171783&r1=171782&r2=171783&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaType.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaType.cpp Mon Jan  7 14:03:16 2013
> @@ -1269,6 +1269,12 @@
>                                             S.LangOpts.GNUMode).isInvalid();
>  }
>
> +/// \brief Determine whether the given type is a POD or standard-layout type,
> +/// as appropriate for the C++ language options.
> +static bool isPODType(QualType T, ASTContext &Context) {
> +  return Context.getLangOpts().CPlusPlus11? T.isCXX11PODType(Context)
> +                                          : T.isCXX98PODType(Context);

This looks equivalent to QualType::isPODType, which the code used to
call. The added test appears to pass without this change.

> +}
>
>  /// \brief Build an array type.
>  ///
> @@ -1442,8 +1448,8 @@
>        // Prohibit the use of non-POD types in VLAs.
>        QualType BaseT = Context.getBaseElementType(T);
>        if (!T->isDependentType() &&
> -          !BaseT.isPODType(Context) &&
> -          !BaseT->isObjCLifetimeType()) {
> +          !BaseT->isObjCLifetimeType() &&
> +          !isPODType(BaseT, Context)) {
>          Diag(Loc, diag::err_vla_non_pod)
>            << BaseT;
>          return QualType();
>
> Added: cfe/trunk/test/SemaCXX/c99-variable-length-array-cxx11.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/c99-variable-length-array-cxx11.cpp?rev=171783&view=auto
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/c99-variable-length-array-cxx11.cpp (added)
> +++ cfe/trunk/test/SemaCXX/c99-variable-length-array-cxx11.cpp Mon Jan  7 14:03:16 2013
> @@ -0,0 +1,26 @@
> +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wvla %s
> +struct StillPOD {
> +  StillPOD() = default;
> +};
> +
> +struct StillPOD2 {
> +  StillPOD np;
> +};
> +
> +struct NonPOD {
> +  NonPOD(int) {}
> +};
> +
> +struct POD {
> +  int x;
> +  int y;
> +};
> +
> +// We allow VLAs of POD types, only.
> +void vla(int N) {
> +  int array1[N]; // expected-warning{{variable length arrays are a C99 feature}}
> +  POD array2[N]; // expected-warning{{variable length arrays are a C99 feature}}
> +  StillPOD array3[N]; // expected-warning{{variable length arrays are a C99 feature}}
> +  StillPOD2 array4[N][3]; // expected-warning{{variable length arrays are a C99 feature}}
> +  NonPOD array5[N]; // expected-error{{variable length array of non-POD element type 'NonPOD'}}
> +}
>
>
> _______________________________________________
> 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