public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/116439] New: [14/15 Regression] decltype(auto) in return type of lambda uses the type of the outer scope, not the capture
@ 2024-08-21 10:18 valentin at tolmer dot fr
  2024-08-21 10:49 ` [Bug c++/116439] " rguenth at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: valentin at tolmer dot fr @ 2024-08-21 10:18 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 116439
           Summary: [14/15 Regression] decltype(auto) in return type of
                    lambda uses the type of the outer scope, not the
                    capture
           Product: gcc
           Version: 14.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: valentin at tolmer dot fr
  Target Milestone: ---

$ cat source.cpp
struct S {
  S() = default;
  S(const S&) = delete;
};

int main() {
  S source;
  [&] -> decltype(auto) {
    return source;
  }();
}
$ g++ -std=c++23 source.cpp
source.cpp: In lambda function:
source.cpp:9:12: error: use of deleted function 'S::S(const S&)'
    9 |     return source;
      |            ^~~~~~
source.cpp:3:3: note: declared here
    3 |   S(const S&) = delete;
      |   ^
source.cpp:9:12: note: use '-fdiagnostics-all-candidates' to display considered
candidates
    9 |     return source;
      |            ^~~~~~
Compiler returned: 1

AFAIU, starting from 14.1 the decltype(auto) deduces the type from the `S
source;`, the outer variable, rather than the implicit by-ref capture of the
same name. Writing `return (source);` correctly deduces the reference.
Introducing an explicitly named capture `[&source = source]` correctly deduces
the reference.
GCC 13.3 and below returns a reference.

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

end of thread, other threads:[~2024-08-23 15:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-21 10:18 [Bug c++/116439] New: [14/15 Regression] decltype(auto) in return type of lambda uses the type of the outer scope, not the capture valentin at tolmer dot fr
2024-08-21 10:49 ` [Bug c++/116439] " rguenth at gcc dot gnu.org
2024-08-21 14:57 ` mpolacek at gcc dot gnu.org
2024-08-22 15:04 ` ppalka at gcc dot gnu.org
2024-08-23 13:56 ` valentin at tolmer dot fr
2024-08-23 15:02 ` ppalka at gcc dot gnu.org
2024-08-23 15:06 ` 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).