public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96330] New: Constexpr variables cannot be used in the template context.
@ 2020-07-27 11:55 steve_green at qq dot com
  2020-07-27 15:35 ` [Bug c++/96330] " jakub at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: steve_green at qq dot com @ 2020-07-27 11:55 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96330
           Summary: Constexpr variables cannot be used in the template
                    context.
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: steve_green at qq dot com
  Target Milestone: ---

demo code:
struct foo_t {
    template<class T>
        static constexpr bool bar = true;
};
inline constexpr foo_t foo{};

template<class T>
    struct baz {
        static_assert(foo.bar<T>); // bug in clang (before instantiation) and
gcc (during instantiation)
        static_assert(foo_t::bar<T>); // OK
    };

int main()
{
    static_assert(foo.bar<void>, ""); // OK
    static_assert(foo_t::bar<void>, ""); // OK
    static_cast<void>(baz<void>{});
}

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

* [Bug c++/96330] Constexpr variables cannot be used in the template context.
  2020-07-27 11:55 [Bug c++/96330] New: Constexpr variables cannot be used in the template context steve_green at qq dot com
@ 2020-07-27 15:35 ` jakub at gcc dot gnu.org
  2021-03-05 16:43 ` ppalka at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-07-27 15:35 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Tried
--- gcc/cp/pt.c.jj      2020-07-27 10:38:19.000000000 +0200
+++ gcc/cp/pt.c 2020-07-27 17:25:09.748240198 +0200
@@ -16838,14 +16838,17 @@ tsubst_copy (tree t, tree args, tsubst_f
     case TEMPLATE_ID_EXPR:
       {
        /* Substituted template arguments */
-       tree fn = TREE_OPERAND (t, 0);
+       tree expr = TREE_OPERAND (t, 0);
        tree targs = TREE_OPERAND (t, 1);

-       fn = tsubst_copy (fn, args, complain, in_decl);
+       expr = tsubst_copy (expr, args, complain, in_decl);
        if (targs)
          targs = tsubst_template_args (targs, args, complain, in_decl);

-       return lookup_template_function (fn, targs);
+        if (variable_template_p (expr))
+         return lookup_and_finish_template_variable (expr, targs, complain);
+       else
+         return lookup_template_function (expr, targs);
       }

     case TREE_LIST:
but that just means an ICE elsewhere.

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

* [Bug c++/96330] Constexpr variables cannot be used in the template context.
  2020-07-27 11:55 [Bug c++/96330] New: Constexpr variables cannot be used in the template context steve_green at qq dot com
  2020-07-27 15:35 ` [Bug c++/96330] " jakub at gcc dot gnu.org
@ 2021-03-05 16:43 ` ppalka at gcc dot gnu.org
  2021-03-06  5:08 ` cvs-commit at gcc dot gnu.org
  2021-03-06 15:26 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-03-05 16:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #1)
> Tried
> --- gcc/cp/pt.c.jj	2020-07-27 10:38:19.000000000 +0200
> +++ gcc/cp/pt.c	2020-07-27 17:25:09.748240198 +0200
> @@ -16838,14 +16838,17 @@ tsubst_copy (tree t, tree args, tsubst_f
>      case TEMPLATE_ID_EXPR:
>        {
>  	/* Substituted template arguments */
> -	tree fn = TREE_OPERAND (t, 0);
> +	tree expr = TREE_OPERAND (t, 0);
>  	tree targs = TREE_OPERAND (t, 1);
>  
> -	fn = tsubst_copy (fn, args, complain, in_decl);
> +	expr = tsubst_copy (expr, args, complain, in_decl);
>  	if (targs)
>  	  targs = tsubst_template_args (targs, args, complain, in_decl);
>  
> -	return lookup_template_function (fn, targs);
> +        if (variable_template_p (expr))
> +	  return lookup_and_finish_template_variable (expr, targs, complain);
> +	else
> +	  return lookup_template_function (expr, targs);
>        }
>  
>      case TREE_LIST:
> but that just means an ICE elsewhere.

Hmm, seems using lookup_template_variable instead of
lookup_and_finish_template_variable works.

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

* [Bug c++/96330] Constexpr variables cannot be used in the template context.
  2020-07-27 11:55 [Bug c++/96330] New: Constexpr variables cannot be used in the template context steve_green at qq dot com
  2020-07-27 15:35 ` [Bug c++/96330] " jakub at gcc dot gnu.org
  2021-03-05 16:43 ` ppalka at gcc dot gnu.org
@ 2021-03-06  5:08 ` cvs-commit at gcc dot gnu.org
  2021-03-06 15:26 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-03-06  5:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:574e7601829733d7cae20b5dc7034b876cc76b30

commit r11-7541-g574e7601829733d7cae20b5dc7034b876cc76b30
Author: Patrick Palka <ppalka@redhat.com>
Date:   Sat Mar 6 00:07:43 2021 -0500

    c++: Fix tsubsting member variable template-id [PR96330]

    This makes tsubst_copy appropriately handle a variable template-id, which
    in turn fixes tsubsting a COMPONENT_REF whose member operand is known at
    parse time to be a variable template-id, as in the initialization of 'x'
    in the first testcase.  Previously, we rejected this testcase with the
    error "foo_t::bar<T> is not a function template", issued from
    lookup_template_fuction.

    We were already properly handling the analagous case where the object
    operand of the COMPONENT_REF is dependent (and so the member operand is
    a dependent template name), but there doesn't seems to be existing test
    coverage for this, hence the second testcase below.

    gcc/cp/ChangeLog:

            PR c++/96330
            * pt.c (tsubst_copy) <case TEMPLATE_ID_EXPR>: Rename local
            variable 'fn' to 'tmpl'.  Handle a variable template-id by
            calling lookup_template_variable.

    gcc/testsuite/ChangeLog:

            PR c++/96330
            * g++.dg/cpp1y/var-templ68.C: New test.
            * g++.dg/cpp1y/var-templ68a.C: New test.

    Co-authored-by: Jakub Jelinek <jakub@redhat.com>

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

* [Bug c++/96330] Constexpr variables cannot be used in the template context.
  2020-07-27 11:55 [Bug c++/96330] New: Constexpr variables cannot be used in the template context steve_green at qq dot com
                   ` (2 preceding siblings ...)
  2021-03-06  5:08 ` cvs-commit at gcc dot gnu.org
@ 2021-03-06 15:26 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-03-06 15:26 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.0
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 11.  Thanks for the bug report!

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

end of thread, other threads:[~2021-03-06 15:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-27 11:55 [Bug c++/96330] New: Constexpr variables cannot be used in the template context steve_green at qq dot com
2020-07-27 15:35 ` [Bug c++/96330] " jakub at gcc dot gnu.org
2021-03-05 16:43 ` ppalka at gcc dot gnu.org
2021-03-06  5:08 ` cvs-commit at gcc dot gnu.org
2021-03-06 15:26 ` ppalka 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).