public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96410] New: A lambda with a template parameter list using C++20 requires clauses is not usable in a constant expression
@ 2020-08-01 12:20 hewillk at gmail dot com
  2020-08-01 14:49 ` [Bug c++/96410] A lambda with a template parameter list inside the template function " hewillk at gmail dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: hewillk at gmail dot com @ 2020-08-01 12:20 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96410
           Summary: A lambda with a template parameter list using C++20
                    requires clauses is not usable in a constant
                    expression
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hewillk at gmail dot com
  Target Milestone: ---

Created attachment 48980
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48980&action=edit
the preprocessed file

The following code:


#include <concepts>

template <typename T>
void f(T t) {
  auto g = []<typename U>(U u) {
    if constexpr (requires { std::integral<U>; });
  };
  g(t);
}

int main()
{
  f(1);
}


will occurs compile error:


<source>: In instantiation of 'void f(T) [with T = int]':
<source>:13:6:   required from here
/opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/concepts:102:13:  
required by the constraints of 'template<class _Tp> concept std::integral'
/opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/concepts:102:24: error:
the value of 'std::is_integral_v<U>' is not usable in a constant expression
  102 |     concept integral = is_integral_v<_Tp>;
      |                        ^~~~~~~~~~~~~~~~~~
In file included from
/opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/concepts:44,
                 from <source>:1:
/opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/type_traits:3031:25: note:
'std::is_integral_v<U>' used in its own initializer
 3031 |   inline constexpr bool is_integral_v = is_integral<_Tp>::value;
      |                         ^~~~~~~~~~~~~
ASM generation compiler returned: 1


This seems weird since the type U can be deduced in the compiler time.
command line:

$ gcc -v -save-temps -std=c++20 main.cpp 
Using built-in specs.
COLLECT_GCC=/usr/local/bin/gcc-10
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/10.1.0/libexec/gcc/x86_64-apple-darwin17/10.1.0/lto-wrapper
Target: x86_64-apple-darwin17
Configured with: ../configure --build=x86_64-apple-darwin17
--prefix=/usr/local/Cellar/gcc/10.1.0
--libdir=/usr/local/Cellar/gcc/10.1.0/lib/gcc/10 --disable-nls
--enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran
--program-suffix=-10 --with-gmp=/usr/local/opt/gmp
--with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc
--with-isl=/usr/local/opt/isl --with-system-zlib --with-pkgversion='Homebrew
GCC 10.1.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues
--disable-multilib SED=/usr/bin/sed
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.1.0 (Homebrew GCC 10.1.0) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++2a'
'-mmacosx-version-min=10.13.0' '-asm_macosx_version_min=10.13' '-mtune=core2'
 /usr/local/Cellar/gcc/10.1.0/libexec/gcc/x86_64-apple-darwin17/10.1.0/cc1plus
-E -quiet -v -D__DYNAMIC__ main.cpp -fPIC -mmacosx-version-min=10.13.0
-mtune=core2 -std=c++2a -fpch-preprocess -o main.ii
ignoring duplicate directory "/usr/local/include"
ignoring nonexistent directory
"/usr/local/Cellar/gcc/10.1.0/lib/gcc/10/gcc/x86_64-apple-darwin17/10.1.0/../../../../../../x86_64-apple-darwin17/include"
#include "..." search starts here:
#include <...> search starts here:
 .
 /usr/local/include

/usr/local/Cellar/gcc/10.1.0/lib/gcc/10/gcc/x86_64-apple-darwin17/10.1.0/../../../../../../include/c++/10.1.0

/usr/local/Cellar/gcc/10.1.0/lib/gcc/10/gcc/x86_64-apple-darwin17/10.1.0/../../../../../../include/c++/10.1.0/x86_64-apple-darwin17

/usr/local/Cellar/gcc/10.1.0/lib/gcc/10/gcc/x86_64-apple-darwin17/10.1.0/../../../../../../include/c++/10.1.0/backward

/usr/local/Cellar/gcc/10.1.0/lib/gcc/10/gcc/x86_64-apple-darwin17/10.1.0/include
 /usr/local/Cellar/gcc/10.1.0/include

/usr/local/Cellar/gcc/10.1.0/lib/gcc/10/gcc/x86_64-apple-darwin17/10.1.0/include-fixed
 /usr/include
 /System/Library/Frameworks
 /Library/Frameworks
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++2a'
'-mmacosx-version-min=10.13.0' '-asm_macosx_version_min=10.13' '-mtune=core2'
 /usr/local/Cellar/gcc/10.1.0/libexec/gcc/x86_64-apple-darwin17/10.1.0/cc1plus
-fpreprocessed main.ii -fPIC -quiet -dumpbase main.cpp
-mmacosx-version-min=10.13.0 -mtune=core2 -auxbase main -std=c++2a -version -o
main.s
GNU C++17 (Homebrew GCC 10.1.0) version 10.1.0 (x86_64-apple-darwin17)
        compiled by GNU C version 10.1.0, GMP version 6.2.0, MPFR version
4.0.2, MPC version 1.1.0, isl version isl-0.22.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++17 (Homebrew GCC 10.1.0) version 10.1.0 (x86_64-apple-darwin17)
        compiled by GNU C version 10.1.0, GMP version 6.2.0, MPFR version
4.0.2, MPC version 1.1.0, isl version isl-0.22.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: b1074358e29f54f1a357a06623845700
In file included from main.cpp:1:
main.cpp: In instantiation of 'void f(T) [with T = int]':
main.cpp:13:6:   required from here
/usr/local/Cellar/gcc/10.1.0/include/c++/10.1.0/concepts:102:13:   required by
the constraints of 'template<class _Tp> concept std::integral'
/usr/local/Cellar/gcc/10.1.0/include/c++/10.1.0/concepts:102:24: error: the
value of 'std::is_integral_v<U>' is not usable in a constant expression
  102 |     concept integral = is_integral_v<_Tp>;
      |                        ^~~~~~~~~~~~~~~~~~
In file included from
/usr/local/Cellar/gcc/10.1.0/include/c++/10.1.0/concepts:44,
                 from main.cpp:1:
/usr/local/Cellar/gcc/10.1.0/include/c++/10.1.0/type_traits:3031:25: note:
'std::is_integral_v<U>' used in its own initializer
 3031 |   inline constexpr bool is_integral_v = is_integral<_Tp>::value;
      |                         ^~~~~~~~~~~~~

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

* [Bug c++/96410] A lambda with a template parameter list inside the template function using C++20 requires clauses is not usable in a constant expression
  2020-08-01 12:20 [Bug c++/96410] New: A lambda with a template parameter list using C++20 requires clauses is not usable in a constant expression hewillk at gmail dot com
@ 2020-08-01 14:49 ` hewillk at gmail dot com
  2020-08-03 12:28 ` ppalka at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: hewillk at gmail dot com @ 2020-08-01 14:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from 康桓瑋 <hewillk at gmail dot com> ---
Equivalent example:
https://godbolt.org/z/chYW3c

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

* [Bug c++/96410] A lambda with a template parameter list inside the template function using C++20 requires clauses is not usable in a constant expression
  2020-08-01 12:20 [Bug c++/96410] New: A lambda with a template parameter list using C++20 requires clauses is not usable in a constant expression hewillk at gmail dot com
  2020-08-01 14:49 ` [Bug c++/96410] A lambda with a template parameter list inside the template function " hewillk at gmail dot com
@ 2020-08-03 12:28 ` ppalka at gcc dot gnu.org
  2020-08-03 12:30 ` ppalka at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-08-03 12:28 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2020-08-03
     Ever confirmed|0                           |1
   Target Milestone|---                         |10.3
                 CC|                            |ppalka at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
      Known to fail|                            |10.1.0, 10.2.0, 11.0

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Confirmed on the 10 branch and trunk.

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

* [Bug c++/96410] A lambda with a template parameter list inside the template function using C++20 requires clauses is not usable in a constant expression
  2020-08-01 12:20 [Bug c++/96410] New: A lambda with a template parameter list using C++20 requires clauses is not usable in a constant expression hewillk at gmail dot com
  2020-08-01 14:49 ` [Bug c++/96410] A lambda with a template parameter list inside the template function " hewillk at gmail dot com
  2020-08-03 12:28 ` ppalka at gcc dot gnu.org
@ 2020-08-03 12:30 ` ppalka at gcc dot gnu.org
  2020-08-07 19:20 ` ppalka at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-08-03 12:30 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |barry.revzin at gmail dot com

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

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

* [Bug c++/96410] A lambda with a template parameter list inside the template function using C++20 requires clauses is not usable in a constant expression
  2020-08-01 12:20 [Bug c++/96410] New: A lambda with a template parameter list using C++20 requires clauses is not usable in a constant expression hewillk at gmail dot com
                   ` (2 preceding siblings ...)
  2020-08-03 12:30 ` ppalka at gcc dot gnu.org
@ 2020-08-07 19:20 ` ppalka at gcc dot gnu.org
  2020-09-17 13:30 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-08-07 19:20 UTC (permalink / raw)
  To: gcc-bugs

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

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
             Status|NEW                         |ASSIGNED

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

* [Bug c++/96410] A lambda with a template parameter list inside the template function using C++20 requires clauses is not usable in a constant expression
  2020-08-01 12:20 [Bug c++/96410] New: A lambda with a template parameter list using C++20 requires clauses is not usable in a constant expression hewillk at gmail dot com
                   ` (3 preceding siblings ...)
  2020-08-07 19:20 ` ppalka at gcc dot gnu.org
@ 2020-09-17 13:30 ` cvs-commit at gcc dot gnu.org
  2020-10-22 15:45 ` hewillk at gmail dot com
  2021-01-18 16:44 ` ppalka at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-09-17 13:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 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:b28b621ac67beee81a47adb50b954bcf751570fd

commit r11-3261-gb28b621ac67beee81a47adb50b954bcf751570fd
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Sep 17 09:16:02 2020 -0400

    c++: requires-expressions and partial instantiation [PR96410]

    This patch makes tsubst_requires_expr avoid substituting into a
    requires-expression when partially instantiating a generic lambda.
    This is necessary in general to ensure that we always check requirements
    in lexical order (as in the first testcase below).  A mechanism similar
    to PACK_EXPANSION_EXTRA_ARGS is added to remember template arguments and
    defer substitution of requires-expressions.

    Incidentally, this change also fixes the two mentioned PRs -- the
    problem there is that tsubst_requires_expr was performing semantic
    checks on template trees, and some of the checks are not prepared to
    handle such trees.  With this patch, tsubst_requires_expr no longer
    does any semantic checking at all when processing_template_decl.

    gcc/cp/ChangeLog:

            PR c++/96409
            PR c++/96410
            * constraint.cc (tsubst_requires_expr): Use REQUIRES_EXPR_PARMS
            and REQUIRES_EXPR_REQS.  Use REQUIRES_EXPR_EXTRA_ARGS,
            add_extra_args and build_extra_args to defer substitution until
            we have all the template arguments.
            (finish_requires_expr): Adjust the call to build_min so that
            REQUIRES_EXPR_EXTRA_ARGS gets set to NULL_TREE.
            * cp-tree.def (REQUIRES_EXPR): Give it a third operand.
            * cp-tree.h (REQUIRES_EXPR_PARMS, REQUIRES_EXPR_REQS,
            REQUIRES_EXPR_EXTRA_ARGS): Define.
            (add_extra_args, build_extra_args): Declare.

    gcc/testsuite/ChangeLog:

            PR c++/96409
            PR c++/96410
            * g++.dg/cpp2a/concepts-lambda13.C: New test.
            * g++.dg/cpp2a/concepts-lambda14.C: New test.

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

* [Bug c++/96410] A lambda with a template parameter list inside the template function using C++20 requires clauses is not usable in a constant expression
  2020-08-01 12:20 [Bug c++/96410] New: A lambda with a template parameter list using C++20 requires clauses is not usable in a constant expression hewillk at gmail dot com
                   ` (4 preceding siblings ...)
  2020-09-17 13:30 ` cvs-commit at gcc dot gnu.org
@ 2020-10-22 15:45 ` hewillk at gmail dot com
  2021-01-18 16:44 ` ppalka at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: hewillk at gmail dot com @ 2020-10-22 15:45 UTC (permalink / raw)
  To: gcc-bugs

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

康桓瑋 <hewillk at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from 康桓瑋 <hewillk at gmail dot com> ---
Fixed.

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

* [Bug c++/96410] A lambda with a template parameter list inside the template function using C++20 requires clauses is not usable in a constant expression
  2020-08-01 12:20 [Bug c++/96410] New: A lambda with a template parameter list using C++20 requires clauses is not usable in a constant expression hewillk at gmail dot com
                   ` (5 preceding siblings ...)
  2020-10-22 15:45 ` hewillk at gmail dot com
@ 2021-01-18 16:44 ` ppalka at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-01-18 16:44 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.3                        |11.0

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

end of thread, other threads:[~2021-01-18 16:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-01 12:20 [Bug c++/96410] New: A lambda with a template parameter list using C++20 requires clauses is not usable in a constant expression hewillk at gmail dot com
2020-08-01 14:49 ` [Bug c++/96410] A lambda with a template parameter list inside the template function " hewillk at gmail dot com
2020-08-03 12:28 ` ppalka at gcc dot gnu.org
2020-08-03 12:30 ` ppalka at gcc dot gnu.org
2020-08-07 19:20 ` ppalka at gcc dot gnu.org
2020-09-17 13:30 ` cvs-commit at gcc dot gnu.org
2020-10-22 15:45 ` hewillk at gmail dot com
2021-01-18 16:44 ` 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).