This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++ PATCH] Fix cp_finish_decl error recovery (PR c++/85134)


OK.

On Tue, Apr 3, 2018 at 12:07 PM, Jakub Jelinek <jakub@redhat.com> wrote:

> Hi!
>
> When we clear DECL_DECLARED_CONSTEXPR_P because the decl doesn't have
> literal type, we returned immediately, which unfortunately breaks e.g.
> OpenMP gimplification, as required DECL_EXPR is not emitted for VLA vars.
>
> This patch instead of returning immediately just clears it and so that
> we don't ICE on constexpr-ice19.C also clears init and DECL_EXTERNAL for
> static data members (or should we return immediately for the static data
> members like we used to do and only fall through for other decls)?
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2018-04-03  Jakub Jelinek  <jakub@redhat.com>
>
>         PR c++/85134
>         * decl.c (cp_finish_decl): If ensure_literal_type_for_
> constexpr_object
>         fails, after clearing DECL_DECLARED_CONSTEXPR_P don't return early,
>         instead for static data members clear init and set DECL_EXTERNAL.
>
>         * g++.dg/gomp/pr85134.C: New test.
>         * g++.dg/cpp0x/constexpr-ice19.C: Expect one further error.
>
> --- gcc/cp/decl.c.jj    2018-03-27 12:54:48.049242949 +0200
> +++ gcc/cp/decl.c       2018-04-03 11:48:40.396539609 +0200
> @@ -6923,11 +6923,14 @@ cp_finish_decl (tree decl, tree init, bo
>        cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
>      }
>
> -  if (ensure_literal_type_for_constexpr_object (decl)
> -      == error_mark_node)
> +  if (ensure_literal_type_for_constexpr_object (decl) == error_mark_node)
>      {
>        DECL_DECLARED_CONSTEXPR_P (decl) = 0;
> -      return;
> +      if (VAR_P (decl) && DECL_CLASS_SCOPE_P (decl))
> +       {
> +         init = NULL_TREE;
> +         DECL_EXTERNAL (decl) = 1;
> +       }
>      }
>
>    if (VAR_P (decl)
> --- gcc/testsuite/g++.dg/gomp/pr85134.C.jj      2018-04-03
> 11:06:22.533539818 +0200
> +++ gcc/testsuite/g++.dg/gomp/pr85134.C 2018-04-03 11:06:13.333540153
> +0200
> @@ -0,0 +1,11 @@
> +// PR c++/85134
> +// { dg-do compile }
> +// { dg-options "-std=c++14 -fopenmp" }
> +
> +void
> +foo (int i)
> +{
> +  constexpr int x[i] = {};     // { dg-error "'constexpr' variable 'x'
> has variably-modified type" }
> +#pragma omp parallel shared(x)
> +  ;
> +}
> --- gcc/testsuite/g++.dg/cpp0x/constexpr-ice19.C.jj     2018-01-17
> 22:00:11.747228288 +0100
> +++ gcc/testsuite/g++.dg/cpp0x/constexpr-ice19.C        2018-04-03
> 11:50:28.203541642 +0200
> @@ -9,5 +9,5 @@ struct A
>
>  struct B
>  {
> -  static constexpr A a {};  // { dg-error "not literal" }
> +  static constexpr A a {};  // { dg-error "not literal|in-class
> initialization" }
>  };
>
>         Jakub
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]