public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94673] New: [concepts] What is the return type of local parameters of requires expressions?
@ 2020-04-20 17:18 gcc-bugs at marehr dot dialup.fu-berlin.de
  2020-04-20 17:43 ` [Bug c++/94673] " gcc-bugs at marehr dot dialup.fu-berlin.de
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gcc-bugs at marehr dot dialup.fu-berlin.de @ 2020-04-20 17:18 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94673
           Summary: [concepts] What is the return type of local parameters
                    of requires expressions?
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc-bugs at marehr dot dialup.fu-berlin.de
  Target Milestone: ---

What should I expect when I write the following concept:

```c++
#include <utility>
#include <type_traits>

template <typename t, typename u>
concept same_as = std::is_same_v<t, u>;

template <typename t>
concept foo = requires(t v)
{
    {v} -> same_as<t>;
};

static_assert(foo<int>); // gcc 9 / clang
static_assert(foo<int &>); // clang
static_assert(foo<int const &>); // clang
```

https://godbolt.org/z/rRkCzE

* clang says that the type of the expression `v` is `t`.
* gcc 9 partially agreed on this for `foo<int>`.
* gcc 10 rejects all of them
* msvc has the same opinion as gcc10, but also fails to provide an answer why.


gcc10 gives me an (improvable?) reason why the concept failed:

```
<source>:13:15: note: constraints not satisfied
<source>:8:9:   required by the constraints of 'template<class t> concept foo'
<source>:8:15:   in requirements with 'int v'
<source>:10:6: note: 'v' does not satisfy return-type-requirement
```

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

* [Bug c++/94673] [concepts] What is the return type of local parameters of requires expressions?
  2020-04-20 17:18 [Bug c++/94673] New: [concepts] What is the return type of local parameters of requires expressions? gcc-bugs at marehr dot dialup.fu-berlin.de
@ 2020-04-20 17:43 ` gcc-bugs at marehr dot dialup.fu-berlin.de
  2021-09-20 21:23 ` arthur.j.odwyer at gmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: gcc-bugs at marehr dot dialup.fu-berlin.de @ 2020-04-20 17:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from gcc-bugs at marehr dot dialup.fu-berlin.de ---
After playing with this a bit more, I found out that clang actually behaves
differently:

```c++
#include <utility>
#include <type_traits>

template <typename t, typename u>
concept same_as = std::is_same_v<t, u>;

template <typename t>
concept foo = requires(t v)
{
    {v} -> same_as<t &>;
};

// all of them work with gcc and msvc
static_assert(foo<int>); // fails with clang
static_assert(foo<int const>); // fails with clang
static_assert(foo<int &&>); // fails with clang
static_assert(foo<int &>);
static_assert(foo<int const &>);
```

https://godbolt.org/z/MGpfZF

I created an issue at https://bugs.llvm.org/show_bug.cgi?id=45622

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

* [Bug c++/94673] [concepts] What is the return type of local parameters of requires expressions?
  2020-04-20 17:18 [Bug c++/94673] New: [concepts] What is the return type of local parameters of requires expressions? gcc-bugs at marehr dot dialup.fu-berlin.de
  2020-04-20 17:43 ` [Bug c++/94673] " gcc-bugs at marehr dot dialup.fu-berlin.de
@ 2021-09-20 21:23 ` arthur.j.odwyer at gmail dot com
  2021-09-20 22:48 ` gcc-bugs at marehr dot dialup.fu-berlin.de
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: arthur.j.odwyer at gmail dot com @ 2021-09-20 21:23 UTC (permalink / raw)
  To: gcc-bugs

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

Arthur O'Dwyer <arthur.j.odwyer at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |arthur.j.odwyer at gmail dot com

--- Comment #2 from Arthur O'Dwyer <arthur.j.odwyer at gmail dot com> ---
Yes, this is/was a Clang bug; a return-type-requirement should be applied to
decltype((expr)), but Clang was incorrectly applying the requirement to
decltype(expr).

I think this can now be closed as "not a bug" (the bug was in Clang, not GCC).

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

* [Bug c++/94673] [concepts] What is the return type of local parameters of requires expressions?
  2020-04-20 17:18 [Bug c++/94673] New: [concepts] What is the return type of local parameters of requires expressions? gcc-bugs at marehr dot dialup.fu-berlin.de
  2020-04-20 17:43 ` [Bug c++/94673] " gcc-bugs at marehr dot dialup.fu-berlin.de
  2021-09-20 21:23 ` arthur.j.odwyer at gmail dot com
@ 2021-09-20 22:48 ` gcc-bugs at marehr dot dialup.fu-berlin.de
  2021-09-21 17:48 ` ppalka at gcc dot gnu.org
  2021-09-21 19:00 ` gcc-bugs at marehr dot dialup.fu-berlin.de
  4 siblings, 0 replies; 6+ messages in thread
From: gcc-bugs at marehr dot dialup.fu-berlin.de @ 2021-09-20 22:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from gcc-bugs at marehr dot dialup.fu-berlin.de ---
I think this bug should be changed to a request to improve the diagnostics.

The diagnostic says:

```
<source>:13:15: note: constraints not satisfied
<source>:8:9:   required by the constraints of 'template<class t> concept foo'
<source>:8:15:   in requirements with 't v' [with t = int]
<source>:10:6: note: 'v' does not satisfy return-type-requirement
   10 |     {v} -> same_as<t>;
      |      ^
```

If you don't know that `{v}` should be read as `{(v)}`, it is confusing that
the diagnostic says that `'t v' [with t = int]` does not satisfy that the type
of the expression `{ v }` is `t`.

I think the diagnostic for the return-type-requirement should add the reason /
diagnostic why it isn't fulfilled, so basically the same reason that
`static_assert(std::same_as<decltype((v)), int>);` would give.

> note: the expression 'is_same_v<_Tp, _Up> [with _Tp = int&; _Up = int]' evaluated to 'false'
>   57 |       concept __same_as = std::is_same_v<_Tp, _Up>;
>      |                           ~~~~~^~~~~~~~~~~~~~~~~~~

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

* [Bug c++/94673] [concepts] What is the return type of local parameters of requires expressions?
  2020-04-20 17:18 [Bug c++/94673] New: [concepts] What is the return type of local parameters of requires expressions? gcc-bugs at marehr dot dialup.fu-berlin.de
                   ` (2 preceding siblings ...)
  2021-09-20 22:48 ` gcc-bugs at marehr dot dialup.fu-berlin.de
@ 2021-09-21 17:48 ` ppalka at gcc dot gnu.org
  2021-09-21 19:00 ` gcc-bugs at marehr dot dialup.fu-berlin.de
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-09-21 17:48 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to gcc-bugs from comment #3)
> I think this bug should be changed to a request to improve the diagnostics.
> 
> The diagnostic says:
> 
> ```
> <source>:13:15: note: constraints not satisfied
> <source>:8:9:   required by the constraints of 'template<class t> concept
> foo'
> <source>:8:15:   in requirements with 't v' [with t = int]
> <source>:10:6: note: 'v' does not satisfy return-type-requirement
>    10 |     {v} -> same_as<t>;
>       |      ^
> ```
> 
> If you don't know that `{v}` should be read as `{(v)}`, it is confusing that
> the diagnostic says that `'t v' [with t = int]` does not satisfy that the
> type of the expression `{ v }` is `t`.
> 
> I think the diagnostic for the return-type-requirement should add the reason
> / diagnostic why it isn't fulfilled, so basically the same reason that
> `static_assert(std::same_as<decltype((v)), int>);` would give.
> 
> > note: the expression 'is_same_v<_Tp, _Up> [with _Tp = int&; _Up = int]' evaluated to 'false'
> >   57 |       concept __same_as = std::is_same_v<_Tp, _Up>;
> >      |                           ~~~~~^~~~~~~~~~~~~~~~~~~

Don't we already do this with -fconcepts-diagnostics-depth=2 ?

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

* [Bug c++/94673] [concepts] What is the return type of local parameters of requires expressions?
  2020-04-20 17:18 [Bug c++/94673] New: [concepts] What is the return type of local parameters of requires expressions? gcc-bugs at marehr dot dialup.fu-berlin.de
                   ` (3 preceding siblings ...)
  2021-09-21 17:48 ` ppalka at gcc dot gnu.org
@ 2021-09-21 19:00 ` gcc-bugs at marehr dot dialup.fu-berlin.de
  4 siblings, 0 replies; 6+ messages in thread
From: gcc-bugs at marehr dot dialup.fu-berlin.de @ 2021-09-21 19:00 UTC (permalink / raw)
  To: gcc-bugs

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

gcc-bugs at marehr dot dialup.fu-berlin.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |WORKSFORME
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #5 from gcc-bugs at marehr dot dialup.fu-berlin.de ---
(In reply to Patrick Palka from comment #4)
> Don't we already do this with -fconcepts-diagnostics-depth=2 ?

You are right, sorry! Haven't checked that again thoroughly, and it seems that
you do. 

> -fconcepts-diagnostics-depth=2

will produce

```
<source>:18:15: error: static assertion failed
   18 | static_assert(foo<int &&>); // fails with clang
      |               ^~~~~~~~~~~
<source>:18:15: note: constraints not satisfied
<source>:9:9:   required by the constraints of 'template<class t> concept foo'
<source>:9:15:   in requirements with 't v' [with t = int&&]
<source>:11:6: note: 'v' does not satisfy return-type-requirement, because
   11 |     {v} -> std::same_as<t &>;
      |     ~^~~~~~~~~~~~~~~~~~~~~~~
<source>:11:6: error: deduced expression type does not satisfy placeholder
constraints
<source>:11:6: note: constraints not satisfied
In file included from
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/compare:39,
                 from
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/bits/stl_pair.h:65,
                 from
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/utility:70,
                 from <source>:1:
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/concepts:57:15:   required
for the satisfaction of '__same_as<_Tp, _Up>' [with _Tp = int&&; _Up = int&]
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/concepts:62:13:   required
for the satisfaction of 'same_as<decltype(auto) [requires
std::same_as<<placeholder>, t&>], t&>' [with decltype(auto) [requires
std::same_as<<placeholder>, t&>] = int&&; t = int&&]
/opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/concepts:57:32: note: the
expression 'is_same_v<_Tp, _Up> [with _Tp = int&&; _Up = int&]' evaluated to
'false'
   57 |       concept __same_as = std::is_same_v<_Tp, _Up>;
      |             
```

It seems that the behaviour changed again in gcc-11:

```
template <typename t>
concept foo = requires(t v)
{
    {v} -> same_as<t &>;
};

static_assert(foo<int &&>); // true in gcc-10, false in gcc-11
```

Thank you again, from my POV can be closed.

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

end of thread, other threads:[~2021-09-21 19:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-20 17:18 [Bug c++/94673] New: [concepts] What is the return type of local parameters of requires expressions? gcc-bugs at marehr dot dialup.fu-berlin.de
2020-04-20 17:43 ` [Bug c++/94673] " gcc-bugs at marehr dot dialup.fu-berlin.de
2021-09-20 21:23 ` arthur.j.odwyer at gmail dot com
2021-09-20 22:48 ` gcc-bugs at marehr dot dialup.fu-berlin.de
2021-09-21 17:48 ` ppalka at gcc dot gnu.org
2021-09-21 19:00 ` gcc-bugs at marehr dot dialup.fu-berlin.de

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).