public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106211] New: Rejects valid with function template with non-deduced parameters from deduced parameters of another function template
@ 2022-07-06  3:31 davidfromonline at gmail dot com
  2022-07-06 20:59 ` [Bug c++/106211] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: davidfromonline at gmail dot com @ 2022-07-06  3:31 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106211
           Summary: Rejects valid with function template with non-deduced
                    parameters from deduced parameters of another function
                    template
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: davidfromonline at gmail dot com
  Target Milestone: ---

The following valid translation unit

```
template<typename, typename>
concept any = true;

void f() {
        []<typename... Ts>(Ts...) {
                return [](any<Ts> auto..., auto) {};
        }(0)(0, 0);
}
```

is rejected by gcc with the error message:

```
<source>: In function 'void f()':
<source>:7:13: error: no match for call to '(f()::<lambda(Ts
...)>::<lambda(auto:1 ..., auto:2)>) (int, int)'
    5 |         []<typename... Ts>(Ts...) {
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    6 |                 return [](any<Ts> auto..., auto) {};
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    7 |         }(0)(0, 0);
      |         ~~~~^~~~~~
<source>:6:24: note: candidate: 'template<class ... auto:1, class auto:2> 
requires (... && any<auto:1, Ts>) f()::<lambda(Ts ...)>::<lambda(auto:1 ...,
auto:2)>'
    6 |                 return [](any<Ts> auto..., auto) {};
      |                        ^
<source>:6:24: note:   template argument deduction/substitution failed:
<source>:7:13: note:   candidate expects 1 argument, 2 provided
    5 |         []<typename... Ts>(Ts...) {
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    6 |                 return [](any<Ts> auto..., auto) {};
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    7 |         }(0)(0, 0);
      |         ~~~~^~~~~~
Compiler returned: 1
```

See it live: https://godbolt.org/z/c7zxWEbxM

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

* [Bug c++/106211] Rejects valid with function template with non-deduced parameters from deduced parameters of another function template
  2022-07-06  3:31 [Bug c++/106211] New: Rejects valid with function template with non-deduced parameters from deduced parameters of another function template davidfromonline at gmail dot com
@ 2022-07-06 20:59 ` pinskia at gcc dot gnu.org
  2022-07-06 22:22 ` davidfromonline at gmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-07-06 20:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
MSVC also rejects this code:

<source>(8): error C2672: 'operator __surrogate_func': no matching overloaded
function found
<source>(8): error C2780: 'auto f::<lambda_1>::()::<lambda_1>::operator
()(_T3...,_T4) const': expects 2 arguments - 2 provided
<source>(7): note: see declaration of 'f::<lambda_1>::()::<lambda_1>::operator
()'

I am suspecting a bug in clang.

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

* [Bug c++/106211] Rejects valid with function template with non-deduced parameters from deduced parameters of another function template
  2022-07-06  3:31 [Bug c++/106211] New: Rejects valid with function template with non-deduced parameters from deduced parameters of another function template davidfromonline at gmail dot com
  2022-07-06 20:59 ` [Bug c++/106211] " pinskia at gcc dot gnu.org
@ 2022-07-06 22:22 ` davidfromonline at gmail dot com
  2022-07-06 22:34 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: davidfromonline at gmail dot com @ 2022-07-06 22:22 UTC (permalink / raw)
  To: gcc-bugs

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

David Stone <davidfromonline at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |davidfromonline at gmail dot com

--- Comment #2 from David Stone <davidfromonline at gmail dot com> ---
I believe clang is correct here. Here is another version that is also rejected
by gcc and msvc, but accepted by clang:

```
template<typename, typename>
concept any = true;

template<typename... Ts>
void f(Ts... ts) {
        [](any<Ts> auto..., auto) {}(ts..., 2);
}

void g() {
        f(1);
}
```

Which looks basically the same. All three compilers accept if line 10 is
changed from `f(1);` to to `f();`. Further, all three compilers also accept
this minor modification:

```
template<typename... Ts>
void f(Ts... ts) {
        [](Ts..., auto) {}(ts..., 2);
}

void g() {
        f(1);
}
```

Further supporting the view that it's a bug in msvc as well, look at the error
message it gives: "expects 2 arguments - 2 provided". Clearly something fishy
is going on in those compiler internals.

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

* [Bug c++/106211] Rejects valid with function template with non-deduced parameters from deduced parameters of another function template
  2022-07-06  3:31 [Bug c++/106211] New: Rejects valid with function template with non-deduced parameters from deduced parameters of another function template davidfromonline at gmail dot com
  2022-07-06 20:59 ` [Bug c++/106211] " pinskia at gcc dot gnu.org
  2022-07-06 22:22 ` davidfromonline at gmail dot com
@ 2022-07-06 22:34 ` pinskia at gcc dot gnu.org
  2022-07-06 22:39 ` davidfromonline at gmail dot com
  2024-04-11 23:48 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-07-06 22:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The question comes about variadic templates and deduction of auto.

>Further, all three compilers also accept this minor modification:
This one does need any deduction though so it is not even related.

So let's take the slightly reduced testcase:

template<typename, typename>
concept any = true;

auto t = []<typename... Ts>(Ts...) {
    return [](any<Ts> auto... b, auto c) {return c;};
}(1);
auto t1 = t(2, 3);

We have now:
Ts being <int>
so we get:

                return [](any<int> auto, auto) {};

Which is invalid as any<int> is invalid.
Maybe I misunderstand how this works though.

If we remove the any<Ts> then we get the same failure for clang as GCC:
<source>:7:11: error: no matching function for call to object of type '(lambda
at <source>:5:12)'
auto t1 = t(2, 3);
          ^
<source>:5:12: note: candidate function [with b:auto = <>, c:auto = int] not
viable: requires single argument 'c', but 2 arguments were provided
    return [](auto... b, auto c) {return c;};
           ^

Which is to say the problem is the way variadic templates with auto is being
handled. I suspect the concept is being handled incorrectly for clang.

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

* [Bug c++/106211] Rejects valid with function template with non-deduced parameters from deduced parameters of another function template
  2022-07-06  3:31 [Bug c++/106211] New: Rejects valid with function template with non-deduced parameters from deduced parameters of another function template davidfromonline at gmail dot com
                   ` (2 preceding siblings ...)
  2022-07-06 22:34 ` pinskia at gcc dot gnu.org
@ 2022-07-06 22:39 ` davidfromonline at gmail dot com
  2024-04-11 23:48 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: davidfromonline at gmail dot com @ 2022-07-06 22:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from David Stone <davidfromonline at gmail dot com> ---
The types for the first parameters of the inner lambda are deduced in my first
two examples, but the arity is fixed in all of them -- equal to the arity of
the outer function.

Also, `return [](any<int> auto, auto) {};` is perfectly valid. It accepts one
argument that satisfies `any<int>` (which is any type), and another argument
that matches anything -- in other words, two arguments.

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

* [Bug c++/106211] Rejects valid with function template with non-deduced parameters from deduced parameters of another function template
  2022-07-06  3:31 [Bug c++/106211] New: Rejects valid with function template with non-deduced parameters from deduced parameters of another function template davidfromonline at gmail dot com
                   ` (3 preceding siblings ...)
  2022-07-06 22:39 ` davidfromonline at gmail dot com
@ 2024-04-11 23:48 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-11 23:48 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |c++-lambda
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2024-04-11
     Ever confirmed|0                           |1

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

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

end of thread, other threads:[~2024-04-11 23:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-06  3:31 [Bug c++/106211] New: Rejects valid with function template with non-deduced parameters from deduced parameters of another function template davidfromonline at gmail dot com
2022-07-06 20:59 ` [Bug c++/106211] " pinskia at gcc dot gnu.org
2022-07-06 22:22 ` davidfromonline at gmail dot com
2022-07-06 22:34 ` pinskia at gcc dot gnu.org
2022-07-06 22:39 ` davidfromonline at gmail dot com
2024-04-11 23:48 ` pinskia 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).