On Tue, Dec 11, 2018 at 05:39:25PM +0100, Jakub Jelinek wrote:
> Hi!
> 
> As mentioned in the PR, while we allow VLAs in some contexts in C++ as
> an extension, they aren't standard and the standard requires in those spots
> constant expressions, thus __builtin_is_constant_evaluated () needs to be
> true if those sizes are indeed constant expressions.
> 
> Fixed by calling cxx_eval_outermost_constant_expr with
> pretend_const_required too in that case.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2018-12-11  Jakub Jelinek  <ja...@redhat.com>
> 
>       PR c++/88446
>       * cp-tree.h (maybe_constant_value): Add pretend_const_required
>       argument.
>       * constexpr.c (maybe_constant_value): Likewise.  If true, don't
>       cache and call cxx_eval_outermost_constant_expr with true as
>       pretend_const_required.
>       * decl.c (compute_array_index_type_loc): Call maybe_constant_value
>       with true as pretend_const_required.
> 
>       * g++.dg/cpp2a/is-constant-evaluated3.C: New test.
> 
> --- gcc/cp/cp-tree.h.jj       2018-12-07 00:23:15.024998595 +0100
> +++ gcc/cp/cp-tree.h  2018-12-11 13:55:51.933845503 +0100
> @@ -7663,7 +7663,7 @@ extern bool require_rvalue_constant_expr
>  extern bool require_potential_rvalue_constant_expression (tree);
>  extern tree cxx_constant_value                       (tree, tree = 
> NULL_TREE);
>  extern tree cxx_constant_init                        (tree, tree = 
> NULL_TREE);
> -extern tree maybe_constant_value             (tree, tree = NULL_TREE);
> +extern tree maybe_constant_value             (tree, tree = NULL_TREE, bool = 
> false);
>  extern tree maybe_constant_init                      (tree, tree = 
> NULL_TREE, bool = false);
>  extern tree fold_non_dependent_expr          (tree, tsubst_flags_t = 
> tf_warning_or_error);
>  extern tree fold_simple                              (tree);
> --- gcc/cp/constexpr.c.jj     2018-12-11 12:01:27.968941683 +0100
> +++ gcc/cp/constexpr.c        2018-12-11 13:56:50.382890876 +0100
> @@ -5244,7 +5244,7 @@ fold_simple (tree t)
>  static GTY((deletable)) hash_map<tree, tree> *cv_cache;
>  
>  tree
> -maybe_constant_value (tree t, tree decl)
> +maybe_constant_value (tree t, tree decl, bool pretend_const_required)
>  {
>    tree r;
>  

Could you please describe the new param in the comment?

> --- gcc/cp/decl.c.jj  2018-12-07 00:23:15.000000000 +0100
> +++ gcc/cp/decl.c     2018-12-11 13:57:30.779231098 +0100
> @@ -9645,7 +9645,10 @@ compute_array_index_type_loc (location_t
>       {
>         size = instantiate_non_dependent_expr_sfinae (size, complain);
>         size = build_converted_constant_expr (size_type_node, size, complain);
> -       size = maybe_constant_value (size);
> +       /* Pedantically a constant expression is required here and so
> +          __builtin_is_constant_evaluated () should fold to true if it
> +          is successfully folded into a constant.  */
> +       size = maybe_constant_value (size, NULL_TREE, true);

Perhaps use /*pretend_const_required=*/true?

Marek

Reply via email to