public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95127] New: Self-calling lambda with auto return type gives misleading error message
@ 2020-05-14 10:41 xzlsmc at gmail dot com
  2020-05-14 10:48 ` [Bug c++/95127] " xzlsmc at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: xzlsmc at gmail dot com @ 2020-05-14 10:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95127
           Summary: Self-calling lambda with auto return type gives
                    misleading error message
           Product: gcc
           Version: 9.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xzlsmc at gmail dot com
  Target Milestone: ---

$ cat bug.cc
int main() {
  auto f = [](const auto &g, auto x) { return g(g, x); };
  f(f, 0);
}
$ gcc -std=c++14 bug.cc
bug.cc: In instantiation of ‘main()::<lambda(const auto:1&, auto:2)> [with
auto:1 = main()::<lambda(const auto:1&, auto:2)>; auto:2 = int]’:
bug.cc:3:9:   required from here
bug.cc:2:48: error: use of ‘main()::<lambda(const auto:1&, auto:2)> [with
auto:1 = main()::<lambda(const auto:1&, auto:2)>; auto:2 = int]’ before
deduction of ‘auto’
    2 |   auto f = [](const auto &g, auto x) { return g(g, x); };
      |                                               ~^~~~~~

This error message is technically correct, but the `auto' it refers to is very
misleading here: it's the implicit `auto' return type of the lambda expression,
rather than either `auto' argument type.  The message can become clearer if
changed to "use of ... before deduction of _return type_".

GCC version: 9.3.1

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

* [Bug c++/95127] Self-calling lambda with auto return type gives misleading error message
  2020-05-14 10:41 [Bug c++/95127] New: Self-calling lambda with auto return type gives misleading error message xzlsmc at gmail dot com
@ 2020-05-14 10:48 ` xzlsmc at gmail dot com
  2021-08-07  1:43 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: xzlsmc at gmail dot com @ 2020-05-14 10:48 UTC (permalink / raw)
  To: gcc-bugs

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

xzlsmc <xzlsmc at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #48532|0                           |1
        is obsolete|                            |

--- Comment #1 from xzlsmc <xzlsmc at gmail dot com> ---
Created attachment 48534
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48534&action=edit
`gcc -v' and bug.ii stuff

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

* [Bug c++/95127] Self-calling lambda with auto return type gives misleading error message
  2020-05-14 10:41 [Bug c++/95127] New: Self-calling lambda with auto return type gives misleading error message xzlsmc at gmail dot com
  2020-05-14 10:48 ` [Bug c++/95127] " xzlsmc at gmail dot com
@ 2021-08-07  1:43 ` pinskia at gcc dot gnu.org
  2021-09-02  1:22 ` egallager at gcc dot gnu.org
  2021-09-02  1:26 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-07  1:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
All 4 compilers (GCC, ICC, clang and MSVC) I have access to reject this code.

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

* [Bug c++/95127] Self-calling lambda with auto return type gives misleading error message
  2020-05-14 10:41 [Bug c++/95127] New: Self-calling lambda with auto return type gives misleading error message xzlsmc at gmail dot com
  2020-05-14 10:48 ` [Bug c++/95127] " xzlsmc at gmail dot com
  2021-08-07  1:43 ` pinskia at gcc dot gnu.org
@ 2021-09-02  1:22 ` egallager at gcc dot gnu.org
  2021-09-02  1:26 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: egallager at gcc dot gnu.org @ 2021-09-02  1:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> All 4 compilers (GCC, ICC, clang and MSVC) I have access to reject this code.

Could you post their error messages for comparison?

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

* [Bug c++/95127] Self-calling lambda with auto return type gives misleading error message
  2020-05-14 10:41 [Bug c++/95127] New: Self-calling lambda with auto return type gives misleading error message xzlsmc at gmail dot com
                   ` (2 preceding siblings ...)
  2021-09-02  1:22 ` egallager at gcc dot gnu.org
@ 2021-09-02  1:26 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-02  1:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Literally all of the same error message even:
clang:
<source>:2:47: error: function 'operator()<(lambda at <source>:2:12), int>'
with deduced return type cannot be used before it is defined
  auto f = [](const auto &g, auto x) { return g(g, x); };
                                              ^
<source>:3:4: note: in instantiation of function template specialization
'main()::(anonymous class)::operator()<(lambda at <source>:2:12), int>'
requested here
  f(f, 0);
   ^
<source>:2:12: note: 'operator()<(lambda at <source>:2:12), int>' declared here
  auto f = [](const auto &g, auto x) { return g(g, x); };
           ^

ICC:
<source>(2): error: cannot deduce the return type of function "lambda [](const
auto &, auto)->auto [with <auto-1>=lambda [](const auto &, auto)->auto,
<auto-2>=int]" (declared at line 2); it has not been defined
    auto f = [](const auto &g, auto x) { return g(g, x); };
                                                ^
          detected during instantiation of function "lambda [](const auto &,
auto)->auto [with <auto-1>=lambda [](const auto &, auto)->auto, <auto-2>=int]"
at line 3

compilation aborted for <source> (code 2)

MSVC:
<source>(2): error C3779: 'main::<lambda_1>::operator ()': a function that
returns 'auto' cannot be used before it is defined
<source>(2): note: see declaration of 'main::<lambda_1>::operator ()'
<source>(3): note: see reference to function template instantiation 'auto
main::<lambda_1>::operator ()<main::<lambda_1>,int>(const _T1 &,_T2) const'
being compiled
        with
        [
            _T1=main::<lambda_1>,
            _T2=int
        ]

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

end of thread, other threads:[~2021-09-02  1:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-14 10:41 [Bug c++/95127] New: Self-calling lambda with auto return type gives misleading error message xzlsmc at gmail dot com
2020-05-14 10:48 ` [Bug c++/95127] " xzlsmc at gmail dot com
2021-08-07  1:43 ` pinskia at gcc dot gnu.org
2021-09-02  1:22 ` egallager at gcc dot gnu.org
2021-09-02  1:26 ` 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).