public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109876] New: initializer_list not usable in constant expressions in a template
@ 2023-05-16 18:33 barry.revzin at gmail dot com
  2023-05-16 18:40 ` [Bug c++/109876] [10/11/12/13/14 Regression] " mpolacek at gcc dot gnu.org
                   ` (18 more replies)
  0 siblings, 19 replies; 20+ messages in thread
From: barry.revzin at gmail dot com @ 2023-05-16 18:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876

            Bug ID: 109876
           Summary: initializer_list not usable in constant expressions in
                    a template
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

Consider this example:

#include <initializer_list>

template <int S>
struct Array {

};

#ifdef USE_TEMPLATE
template <int N>
#endif
struct Foo
{
  static constexpr std::initializer_list<int> num = { 1, 2 };

  Array<num.size()> ctx;

};

#ifdef USE_TEMPLATE
void f(Foo<5>) { }
#else
void f(Foo) { }
#endif

In all recent versions of gcc, compiling with -DUSE_TEMPLATE fails with an
error like:

<source>:15:17:   in 'constexpr' expansion of
'Foo<N>::num.std::initializer_list<int>::size()'
<source>:15:19: error: the value of 'Foo<N>::num' is not usable in a constant
expression
   15 |   Array<num.size()> ctx;
      |                   ^

This used to work in gcc 7 and gcc 8 (except 8.1), and I don't think there's
anything about Foo being a template that should prevent this from working. The
non-template case works on all gcc versions I've tried.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Bug c++/109876] [10/11/12/13/14 Regression] initializer_list not usable in constant expressions in a template
  2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
@ 2023-05-16 18:40 ` mpolacek at gcc dot gnu.org
  2023-05-16 18:43 ` pinskia at gcc dot gnu.org
                   ` (17 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-05-16 18:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Target Milestone|---                         |10.5
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-05-16
           Priority|P3                          |P2
           Keywords|                            |rejects-valid
            Summary|initializer_list not usable |[10/11/12/13/14 Regression]
                   |in constant expressions in  |initializer_list not usable
                   |a template                  |in constant expressions in
                   |                            |a template
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Stopped working with r8-509-g6064858051d6e0

commit 6064858051d6e07bb89f3384c0d828f07c576c7a
Author: Jason Merrill <jason@redhat.com>
Date:   Tue May 9 09:48:58 2017 -0400

    PR c++/70167 - array prvalue treated as lvalue

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Bug c++/109876] [10/11/12/13/14 Regression] initializer_list not usable in constant expressions in a template
  2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
  2023-05-16 18:40 ` [Bug c++/109876] [10/11/12/13/14 Regression] " mpolacek at gcc dot gnu.org
@ 2023-05-16 18:43 ` pinskia at gcc dot gnu.org
  2023-05-16 18:45 ` mpolacek at gcc dot gnu.org
                   ` (16 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-16 18:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |9.1.0, 9.5.0
   Last reconfirmed|2023-05-16 00:00:00         |
           Priority|P2                          |P3
      Known to work|                            |8.5.0

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Bug c++/109876] [10/11/12/13/14 Regression] initializer_list not usable in constant expressions in a template
  2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
  2023-05-16 18:40 ` [Bug c++/109876] [10/11/12/13/14 Regression] " mpolacek at gcc dot gnu.org
  2023-05-16 18:43 ` pinskia at gcc dot gnu.org
@ 2023-05-16 18:45 ` mpolacek at gcc dot gnu.org
  2023-05-16 18:46 ` pinskia at gcc dot gnu.org
                   ` (15 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-05-16 18:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Bug c++/109876] [10/11/12/13/14 Regression] initializer_list not usable in constant expressions in a template
  2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
                   ` (2 preceding siblings ...)
  2023-05-16 18:45 ` mpolacek at gcc dot gnu.org
@ 2023-05-16 18:46 ` pinskia at gcc dot gnu.org
  2023-05-16 19:13 ` mpolacek at gcc dot gnu.org
                   ` (14 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-16 18:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
What fixed it on the GCC 8 branch?

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Bug c++/109876] [10/11/12/13/14 Regression] initializer_list not usable in constant expressions in a template
  2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
                   ` (3 preceding siblings ...)
  2023-05-16 18:46 ` pinskia at gcc dot gnu.org
@ 2023-05-16 19:13 ` mpolacek at gcc dot gnu.org
  2023-05-18 16:41 ` mpolacek at gcc dot gnu.org
                   ` (13 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-05-16 19:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
On trunk we no longer create a static temporary var for { 1, 2 }, because the
code in finish_compound_literal is now guarded by '&& fcl_context == fcl_c99'
but it's fcl_functional here.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Bug c++/109876] [10/11/12/13/14 Regression] initializer_list not usable in constant expressions in a template
  2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
                   ` (4 preceding siblings ...)
  2023-05-16 19:13 ` mpolacek at gcc dot gnu.org
@ 2023-05-18 16:41 ` mpolacek at gcc dot gnu.org
  2023-05-18 17:07 ` ppalka at gcc dot gnu.org
                   ` (12 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-05-18 16:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Bug c++/109876] [10/11/12/13/14 Regression] initializer_list not usable in constant expressions in a template
  2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
                   ` (5 preceding siblings ...)
  2023-05-18 16:41 ` mpolacek at gcc dot gnu.org
@ 2023-05-18 17:07 ` ppalka at gcc dot gnu.org
  2023-05-18 17:26 ` jason at gcc dot gnu.org
                   ` (11 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-05-18 17:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=89144
                 CC|                            |ppalka at gcc dot gnu.org

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Seems related to PR89144 too -- there we were mishandling defining a
non-dependent static std::initializer_list member variable, here we're
subsequently trying to use it.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Bug c++/109876] [10/11/12/13/14 Regression] initializer_list not usable in constant expressions in a template
  2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
                   ` (6 preceding siblings ...)
  2023-05-18 17:07 ` ppalka at gcc dot gnu.org
@ 2023-05-18 17:26 ` jason at gcc dot gnu.org
  2023-05-19 21:01 ` mpolacek at gcc dot gnu.org
                   ` (10 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: jason at gcc dot gnu.org @ 2023-05-18 17:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> ---
(In reply to Patrick Palka from comment #5)
> Seems related to PR89144 too -- there we were mishandling defining a
> non-dependent static std::initializer_list member variable, here we're
> subsequently trying to use it.

The issue there is that the initializer_list wasn't static, but here it is, so
the array temporary should be as well.  And presumably the problem is that we
aren't representing that lifetime extension in a template.  And checking the
initializer gives up on trying to enforce that.  But then when we try to
evaluate the template argument we find that we don't have a constant value to
work with, and complain.  

Instead, we should probably treat num as value-dependent even though it
actually isn't.  Or fix it to be properly evaluated by representing the
lifetime extension somehow.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Bug c++/109876] [10/11/12/13/14 Regression] initializer_list not usable in constant expressions in a template
  2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
                   ` (7 preceding siblings ...)
  2023-05-18 17:26 ` jason at gcc dot gnu.org
@ 2023-05-19 21:01 ` mpolacek at gcc dot gnu.org
  2023-05-24 20:20 ` mpolacek at gcc dot gnu.org
                   ` (9 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-05-19 21:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876

--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
// PR c++/109876

using size_t = decltype(sizeof 0);

namespace std {
template <class> struct initializer_list {
  const int *_M_array;
  size_t _M_len;
  constexpr size_t size() const { return _M_len; }
};
} // namespace std

template <int> struct Array {};
template <int> void g()
{
  static constexpr std::initializer_list<int> num{2};
  Array<num.size()> ctx;
}

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Bug c++/109876] [10/11/12/13/14 Regression] initializer_list not usable in constant expressions in a template
  2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
                   ` (8 preceding siblings ...)
  2023-05-19 21:01 ` mpolacek at gcc dot gnu.org
@ 2023-05-24 20:20 ` mpolacek at gcc dot gnu.org
  2023-05-24 20:28 ` jason at gcc dot gnu.org
                   ` (8 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-05-24 20:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876

--- Comment #8 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
> Instead, we should probably treat num as value-dependent even though it actually isn't.

An attempt to implement that:

--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -27969,6 +27969,12 @@ value_dependent_expression_p (tree expression)
       else if (TYPE_REF_P (TREE_TYPE (expression)))
    /* FIXME cp_finish_decl doesn't fold reference initializers.  */
    return true;
+      else if (DECL_DECLARED_CONSTEXPR_P (expression)
+          && TREE_STATIC (expression)
+          && !DECL_NAMESPACE_SCOPE_P (expression)
+          && DECL_INITIAL (expression)
+          && TREE_CODE (DECL_INITIAL (expression)) == IMPLICIT_CONV_EXPR)
+   return true;
       return false;

     case DYNAMIC_CAST_EXPR:

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Bug c++/109876] [10/11/12/13/14 Regression] initializer_list not usable in constant expressions in a template
  2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
                   ` (9 preceding siblings ...)
  2023-05-24 20:20 ` mpolacek at gcc dot gnu.org
@ 2023-05-24 20:28 ` jason at gcc dot gnu.org
  2023-05-26 17:02 ` mpolacek at gcc dot gnu.org
                   ` (7 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: jason at gcc dot gnu.org @ 2023-05-24 20:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876

--- Comment #9 from Jason Merrill <jason at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #8)
> > Instead, we should probably treat num as value-dependent even though it actually isn't.
> 
> An attempt to implement that:
> 
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -27969,6 +27969,12 @@ value_dependent_expression_p (tree expression)
>        else if (TYPE_REF_P (TREE_TYPE (expression)))
>     /* FIXME cp_finish_decl doesn't fold reference initializers.  */
>     return true;
> +      else if (DECL_DECLARED_CONSTEXPR_P (expression)
> +          && TREE_STATIC (expression)

I'd expect we could get a similar issue with non-static constexprs.

> +          && !DECL_NAMESPACE_SCOPE_P (expression)

This seems an unnecessary optimization?

> +          && DECL_INITIAL (expression)

Perhaps we also want to return true if DECL_INITIAL is null?

> +          && TREE_CODE (DECL_INITIAL (expression)) == IMPLICIT_CONV_EXPR)

Maybe !TREE_CONSTANT?

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Bug c++/109876] [10/11/12/13/14 Regression] initializer_list not usable in constant expressions in a template
  2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
                   ` (10 preceding siblings ...)
  2023-05-24 20:28 ` jason at gcc dot gnu.org
@ 2023-05-26 17:02 ` mpolacek at gcc dot gnu.org
  2023-05-26 18:08 ` mpolacek at gcc dot gnu.org
                   ` (6 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-05-26 17:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876

--- Comment #10 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
So I have

--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -27969,6 +27969,13 @@ value_dependent_expression_p (tree expression)
       else if (TYPE_REF_P (TREE_TYPE (expression)))
    /* FIXME cp_finish_decl doesn't fold reference initializers.  */
    return true;
+      /* We have a constexpr variable and we're processing a template.  When
+    there's lifetime extension involved (for which finish_compound_literal
+    used to create a temporary), we'll not be able to evaluate the
+    variable until instantiating, so pretend it's value-dependent.  */
+      else if (DECL_DECLARED_CONSTEXPR_P (expression)
+          && !TREE_CONSTANT (expression))
+   return true;
       return false;

     case DYNAMIC_CAST_EXPR:

but that breaks

struct foo {  };

template <const foo & F> void fnc() { } 

void
test()
{
  static constexpr foo a;
  fnc<a>();
}

with:

$ ./cc1plus -quiet nontype-auto16.C 
nontype-auto16.C:6:31: warning: ‘void fnc() [with const foo& F = a]’ used but
never defined
    6 | template <const foo & F> void fnc() { }
      |                               ^~~
nontype-auto16.C:13:1: internal compiler error: Segmentation fault
   13 | }
      | ^
0x19a5624 crash_signal
        /home/mpolacek/src/gcc/gcc/toplev.cc:314
0x7fe161facb1f ???
       
/usr/src/debug/glibc-2.36-9.fc37.x86_64/signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0xcbfe74 tree_check(tree_node const*, char const*, int, char const*, tree_code)
        /home/mpolacek/src/gcc/gcc/tree.h:3795
0x12c2224 symbol_table::decl_assembler_name_hash(tree_node const*)
        /home/mpolacek/src/gcc/gcc/symtab.cc:84

The warning is obviously wrong and the cause for the ICE, I'd say.  test isn't
a function template but uses_template_parms / verify_unstripped_args set p_t_d,
so we still reach the new code.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Bug c++/109876] [10/11/12/13/14 Regression] initializer_list not usable in constant expressions in a template
  2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
                   ` (11 preceding siblings ...)
  2023-05-26 17:02 ` mpolacek at gcc dot gnu.org
@ 2023-05-26 18:08 ` mpolacek at gcc dot gnu.org
  2023-07-07 10:45 ` [Bug c++/109876] [11/12/13/14 " rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-05-26 18:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876

--- Comment #11 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
We never instantiated fnc because mark_used checks

  /* Check this too in case we're within instantiate_non_dependent_expr.  */
  if (DECL_TEMPLATE_INFO (decl)
      && uses_template_parms (DECL_TI_ARGS (decl)))
    return true;

and here uses_template_parms says yes because value_dependent_expression_p says
'a' is value-dep.  Note we can't use in_template_function in v_d_e_p.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Bug c++/109876] [11/12/13/14 Regression] initializer_list not usable in constant expressions in a template
  2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
                   ` (12 preceding siblings ...)
  2023-05-26 18:08 ` mpolacek at gcc dot gnu.org
@ 2023-07-07 10:45 ` rguenth at gcc dot gnu.org
  2023-07-14 17:16 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 10:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.5                        |11.5

--- Comment #12 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10 branch is being closed.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Bug c++/109876] [11/12/13/14 Regression] initializer_list not usable in constant expressions in a template
  2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
                   ` (13 preceding siblings ...)
  2023-07-07 10:45 ` [Bug c++/109876] [11/12/13/14 " rguenth at gcc dot gnu.org
@ 2023-07-14 17:16 ` cvs-commit at gcc dot gnu.org
  2023-07-14 17:18 ` [Bug c++/109876] [11/12/13 " mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-14 17:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876

--- Comment #13 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:b5138df96a93d3b5070c88b8617eabd38cb24ab6

commit r14-2527-gb5138df96a93d3b5070c88b8617eabd38cb24ab6
Author: Marek Polacek <polacek@redhat.com>
Date:   Thu May 25 18:54:18 2023 -0400

    c++: wrong error with static constexpr var in tmpl [PR109876]

    Since r8-509, we'll no longer create a static temporary var for
    the initializer '{ 1, 2 }' for num in the attached test because
    the code in finish_compound_literal is now guarded by
    '&& fcl_context == fcl_c99' but it's fcl_functional here.  This
    causes us to reject num as non-constant when evaluating it in
    a template.

    Jason's idea was to treat num as value-dependent even though it
    actually isn't.  This patch implements that suggestion.

    We weren't marking objects whose type is an empty class type
    constant.  This patch changes that so that v_d_e_p doesn't need
    to check is_really_empty_class.

    Co-authored-by: Jason Merrill <jason@redhat.com>

            PR c++/109876

    gcc/cp/ChangeLog:

            * decl.cc (cp_finish_decl): Set TREE_CONSTANT when initializing
            an object of empty class type.
            * pt.cc (value_dependent_expression_p) <case VAR_DECL>: Treat a
            constexpr-declared non-constant variable as value-dependent.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/constexpr-template12.C: New test.
            * g++.dg/cpp1z/constexpr-template1.C: New test.
            * g++.dg/cpp1z/constexpr-template2.C: New test.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Bug c++/109876] [11/12/13 Regression] initializer_list not usable in constant expressions in a template
  2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
                   ` (14 preceding siblings ...)
  2023-07-14 17:16 ` cvs-commit at gcc dot gnu.org
@ 2023-07-14 17:18 ` mpolacek at gcc dot gnu.org
  2023-07-19 11:26 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  18 siblings, 0 replies; 20+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-07-14 17:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[11/12/13/14 Regression]    |[11/12/13 Regression]
                   |initializer_list not usable |initializer_list not usable
                   |in constant expressions in  |in constant expressions in
                   |a template                  |a template

--- Comment #14 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk so far.  I want to wait a bit before backporting this.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Bug c++/109876] [11/12/13 Regression] initializer_list not usable in constant expressions in a template
  2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
                   ` (15 preceding siblings ...)
  2023-07-14 17:18 ` [Bug c++/109876] [11/12/13 " mpolacek at gcc dot gnu.org
@ 2023-07-19 11:26 ` rguenth at gcc dot gnu.org
  2023-12-12  0:37 ` cvs-commit at gcc dot gnu.org
  2023-12-12  0:39 ` [Bug c++/109876] [11/12 " mpolacek at gcc dot gnu.org
  18 siblings, 0 replies; 20+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-19 11:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |14.0
      Known to fail|                            |13.1.0

--- Comment #15 from Richard Biener <rguenth at gcc dot gnu.org> ---
bit has passed

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Bug c++/109876] [11/12/13 Regression] initializer_list not usable in constant expressions in a template
  2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
                   ` (16 preceding siblings ...)
  2023-07-19 11:26 ` rguenth at gcc dot gnu.org
@ 2023-12-12  0:37 ` cvs-commit at gcc dot gnu.org
  2023-12-12  0:39 ` [Bug c++/109876] [11/12 " mpolacek at gcc dot gnu.org
  18 siblings, 0 replies; 20+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-12  0:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876

--- Comment #16 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:08f4496aa619f9b0e8dbb459452dd96edb870236

commit r13-8146-g08f4496aa619f9b0e8dbb459452dd96edb870236
Author: Marek Polacek <polacek@redhat.com>
Date:   Thu May 25 18:54:18 2023 -0400

    c++: wrong error with static constexpr var in tmpl [PR109876]

    Since r8-509, we'll no longer create a static temporary var for
    the initializer '{ 1, 2 }' for num in the attached test because
    the code in finish_compound_literal is now guarded by
    '&& fcl_context == fcl_c99' but it's fcl_functional here.  This
    causes us to reject num as non-constant when evaluating it in
    a template.

    Jason's idea was to treat num as value-dependent even though it
    actually isn't.  This patch implements that suggestion.

    We weren't marking objects whose type is an empty class type
    constant.  This patch changes that so that v_d_e_p doesn't need
    to check is_really_empty_class.

    Co-authored-by: Jason Merrill <jason@redhat.com>

            PR c++/109876

    gcc/cp/ChangeLog:

            * decl.cc (cp_finish_decl): Set TREE_CONSTANT when initializing
            an object of empty class type.
            * pt.cc (value_dependent_expression_p) <case VAR_DECL>: Treat a
            constexpr-declared non-constant variable as value-dependent.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/constexpr-template12.C: New test.
            * g++.dg/cpp1z/constexpr-template1.C: New test.
            * g++.dg/cpp1z/constexpr-template2.C: New test.

    (cherry picked from commit b5138df96a93d3b5070c88b8617eabd38cb24ab6)

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [Bug c++/109876] [11/12 Regression] initializer_list not usable in constant expressions in a template
  2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
                   ` (17 preceding siblings ...)
  2023-12-12  0:37 ` cvs-commit at gcc dot gnu.org
@ 2023-12-12  0:39 ` mpolacek at gcc dot gnu.org
  18 siblings, 0 replies; 20+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-12-12  0:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109876

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
            Summary|[11/12/13 Regression]       |[11/12 Regression]
                   |initializer_list not usable |initializer_list not usable
                   |in constant expressions in  |in constant expressions in
                   |a template                  |a template

--- Comment #17 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed in GCC 13 and 14.

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2023-12-12  0:39 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-16 18:33 [Bug c++/109876] New: initializer_list not usable in constant expressions in a template barry.revzin at gmail dot com
2023-05-16 18:40 ` [Bug c++/109876] [10/11/12/13/14 Regression] " mpolacek at gcc dot gnu.org
2023-05-16 18:43 ` pinskia at gcc dot gnu.org
2023-05-16 18:45 ` mpolacek at gcc dot gnu.org
2023-05-16 18:46 ` pinskia at gcc dot gnu.org
2023-05-16 19:13 ` mpolacek at gcc dot gnu.org
2023-05-18 16:41 ` mpolacek at gcc dot gnu.org
2023-05-18 17:07 ` ppalka at gcc dot gnu.org
2023-05-18 17:26 ` jason at gcc dot gnu.org
2023-05-19 21:01 ` mpolacek at gcc dot gnu.org
2023-05-24 20:20 ` mpolacek at gcc dot gnu.org
2023-05-24 20:28 ` jason at gcc dot gnu.org
2023-05-26 17:02 ` mpolacek at gcc dot gnu.org
2023-05-26 18:08 ` mpolacek at gcc dot gnu.org
2023-07-07 10:45 ` [Bug c++/109876] [11/12/13/14 " rguenth at gcc dot gnu.org
2023-07-14 17:16 ` cvs-commit at gcc dot gnu.org
2023-07-14 17:18 ` [Bug c++/109876] [11/12/13 " mpolacek at gcc dot gnu.org
2023-07-19 11:26 ` rguenth at gcc dot gnu.org
2023-12-12  0:37 ` cvs-commit at gcc dot gnu.org
2023-12-12  0:39 ` [Bug c++/109876] [11/12 " mpolacek at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).