public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101725] New: simple requirement of parameter in defaulted non-type template parameter considered non-dependent
@ 2021-08-02 13:46 johelegp at gmail dot com
  2021-08-03 16:35 ` [Bug c++/101725] " ppalka at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: johelegp at gmail dot com @ 2021-08-02 13:46 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101725
           Summary: simple requirement of parameter in defaulted non-type
                    template parameter considered non-dependent
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: johelegp at gmail dot com
                CC: johelegp at gmail dot com
  Target Milestone: ---

See https://godbolt.org/z/fer6on13z.
```C++
template<class T, bool V = (requires(T t) { x(t); })> constexpr bool
can_x_yet{V};
template<class T, bool V = (requires { y(*(T*)(0)); })> constexpr bool
can_y_yet{V};
```
The first line fails with:
```
<source>:1:47: error: parameter 't' may not appear in this context
    1 | template<class T, bool V = (requires(T t) { x(t); })> constexpr bool
can_x_yet{V};
      |                                               ^
<source>:1:45: error: there are no arguments to 'x' that depend on a template
parameter, so a declaration of 'x' must be available [-fpermissive]
    1 | template<class T, bool V = (requires(T t) { x(t); })> constexpr bool
can_x_yet{V};
      |                                             ^
<source>:1:45: note: (if you use '-fpermissive', G++ will accept your code, but
allowing the use of an undeclared name is deprecated)
Compiler returned: 1
```

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

* [Bug c++/101725] simple requirement of parameter in defaulted non-type template parameter considered non-dependent
  2021-08-02 13:46 [Bug c++/101725] New: simple requirement of parameter in defaulted non-type template parameter considered non-dependent johelegp at gmail dot com
@ 2021-08-03 16:35 ` ppalka at gcc dot gnu.org
  2021-08-11 20:55 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-08-03 16:35 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
                 CC|                            |ppalka at gcc dot gnu.org
   Last reconfirmed|                            |2021-08-03
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1

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

* [Bug c++/101725] simple requirement of parameter in defaulted non-type template parameter considered non-dependent
  2021-08-02 13:46 [Bug c++/101725] New: simple requirement of parameter in defaulted non-type template parameter considered non-dependent johelegp at gmail dot com
  2021-08-03 16:35 ` [Bug c++/101725] " ppalka at gcc dot gnu.org
@ 2021-08-11 20:55 ` cvs-commit at gcc dot gnu.org
  2021-08-11 21:41 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-08-11 20:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 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:9707d2e5dbb92d2bc990c922461a5a16ae652319

commit r12-2862-g9707d2e5dbb92d2bc990c922461a5a16ae652319
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Aug 11 16:53:53 2021 -0400

    c++: parameterized requires-expr as default argument [PR101725]

    Here we're rejecting the default template argument

      requires (T t) { x(t); }

    because we consider the 't' in the requirement to be a local variable
    (according to local_variable_p), and we generally forbid local variables
    from appearing inside default arguments.  We can perhaps fix this by
    giving special treatment to parameters introduced by requires-expressions,
    but DR 2082 relaxed the restriction about local variables appearing within
    default arguments to permit them inside unevaluated operands thereof.
    So this patch just implements DR 2082 which also fixes this PR since a
    requires-expression is an unevaluated context.

            PR c++/101725
            DR 2082

    gcc/cp/ChangeLog:

            * cp-tree.h (unevaluated_p): Return true for REQUIRES_EXPR.
            * decl.c (local_variable_p_walkfn): Don't walk into unevaluated
            operands.
            * parser.c (cp_parser_primary_expression) <case CPP_NAME>: Never
            reject uses of local variables in unevaluated contexts.
            * tree.c (cp_walk_subtrees) <case REQUIRES_EXPR>: Increment
            cp_unevaluated_operand.  Use cp_walk_tree directly instead of
            WALK_SUBTREE to avoid the goto.  Use REQUIRES_EXPR_REQS instead
            of TREE_OPERAND directly.

    gcc/testsuite/ChangeLog:

            * g++.dg/DRs/dr2082.C: New test.
            * g++.dg/cpp2a/concepts-uneval4.C: New test.

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

* [Bug c++/101725] simple requirement of parameter in defaulted non-type template parameter considered non-dependent
  2021-08-02 13:46 [Bug c++/101725] New: simple requirement of parameter in defaulted non-type template parameter considered non-dependent johelegp at gmail dot com
  2021-08-03 16:35 ` [Bug c++/101725] " ppalka at gcc dot gnu.org
  2021-08-11 20:55 ` cvs-commit at gcc dot gnu.org
@ 2021-08-11 21:41 ` cvs-commit at gcc dot gnu.org
  2021-08-11 21:42 ` ppalka at gcc dot gnu.org
  2021-09-15 18:24 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-08-11 21:41 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

commit r11-8853-gbe45bc283e1821fff463d03d5115cd4db634ed84
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Aug 11 16:53:53 2021 -0400

    c++: parameterized requires-expr as default argument [PR101725]

    Here we're rejecting the default template argument

      requires (T t) { x(t); }

    because we consider the 't' in the requirement to be a local variable
    (according to local_variable_p), and we generally forbid local variables
    from appearing inside default arguments.  We can perhaps fix this by
    giving special treatment to parameters introduced by requires-expressions,
    but DR 2082 relaxed the restriction about local variables appearing within
    default arguments to permit them inside unevaluated operands thereof.
    So this patch just implements DR 2082 which also fixes this PR since a
    requires-expression is an unevaluated context.

            PR c++/101725
            DR 2082

    gcc/cp/ChangeLog:

            * cp-tree.h (unevaluated_p): Return true for REQUIRES_EXPR.
            * decl.c (local_variable_p_walkfn): Don't walk into unevaluated
            operands.
            * parser.c (cp_parser_primary_expression) <case CPP_NAME>: Never
            reject uses of local variables in unevaluated contexts.
            * tree.c (cp_walk_subtrees) <case REQUIRES_EXPR>: Increment
            cp_unevaluated_operand.  Use cp_walk_tree directly instead of
            WALK_SUBTREE to avoid the goto.  Use REQUIRES_EXPR_REQS instead
            of TREE_OPERAND directly.

    gcc/testsuite/ChangeLog:

            * g++.dg/DRs/dr2082.C: New test.
            * g++.dg/cpp2a/concepts-uneval4.C: New test.

    (cherry picked from commit 9707d2e5dbb92d2bc990c922461a5a16ae652319)

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

* [Bug c++/101725] simple requirement of parameter in defaulted non-type template parameter considered non-dependent
  2021-08-02 13:46 [Bug c++/101725] New: simple requirement of parameter in defaulted non-type template parameter considered non-dependent johelegp at gmail dot com
                   ` (2 preceding siblings ...)
  2021-08-11 21:41 ` cvs-commit at gcc dot gnu.org
@ 2021-08-11 21:42 ` ppalka at gcc dot gnu.org
  2021-09-15 18:24 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-08-11 21:42 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.3
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 11.3 and 12.

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

* [Bug c++/101725] simple requirement of parameter in defaulted non-type template parameter considered non-dependent
  2021-08-02 13:46 [Bug c++/101725] New: simple requirement of parameter in defaulted non-type template parameter considered non-dependent johelegp at gmail dot com
                   ` (3 preceding siblings ...)
  2021-08-11 21:42 ` ppalka at gcc dot gnu.org
@ 2021-09-15 18:24 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-09-15 18:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
*** Bug 94499 has been marked as a duplicate of this bug. ***

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

end of thread, other threads:[~2021-09-15 18:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-02 13:46 [Bug c++/101725] New: simple requirement of parameter in defaulted non-type template parameter considered non-dependent johelegp at gmail dot com
2021-08-03 16:35 ` [Bug c++/101725] " ppalka at gcc dot gnu.org
2021-08-11 20:55 ` cvs-commit at gcc dot gnu.org
2021-08-11 21:41 ` cvs-commit at gcc dot gnu.org
2021-08-11 21:42 ` ppalka at gcc dot gnu.org
2021-09-15 18:24 ` 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).