[PATCH] D123319: Change how we handle auto return types for lambda operator() to be consistent with gcc
David Blaikie via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 22 12:52:35 PDT 2022
dblaikie added a comment.
In D123319#3593644 <https://reviews.llvm.org/D123319#3593644>, @aprantl wrote:
> In D123319#3517966 <https://reviews.llvm.org/D123319#3517966>, @dblaikie wrote:
>
>> In D123319#3506745 <https://reviews.llvm.org/D123319#3506745>, @shafik wrote:
>>
>>>
>>
>> What does the linkage name do for your use case? Which cases are missing linkage names/where do they go missing?
>>
>>> I am happy to consider other approaches as well to solving lookup for local lambdas for D105564 <https://reviews.llvm.org/D105564>. Let me know what you think.
>>
>> Why does the return type help perform lookup? What kind of lookup?
>>
>> (again, my take is that "auto" return types probably shouldn't be described at all - we should just not describe functions where we don't know their return types because they're not very useful to know about (overload resolution, yes, but then you can't call them anyway) - but that's a broader argument to make/change to make)
>
> IIUC, the motivating problem is (@shafik please correct me if this isn't it) this:
>
> $ cat /tmp/lambda.cpp
> #include <cstdio>
> int main() {
> auto f = [](){ printf("hi from lambda\n"); return 1;} ;
> f();
> f();
> return f();
> }
> $ clang++ -g /tmp/lambda.cpp -o /tmp/a.out
> $ lldb /tmp/a.out
> (lldb) b 5
> (lldb) r
> (lldb) p f()
> hi from lambda
> (lldb) p auto val = f()
> error: expression failed to parse:
> error: <user expression 1>:1:6: variable has incomplete type 'void'
> auto val = f()
> ^
OK. Thanks - I can reproduce this. Though it seems like the issue isn't about lambdas - but about member functions in general, lambdas or not:
$ cat test.cpp
#include <cstdio>
auto g = []() {
printf("hi from non-local lambda\n");
return 1;
};
struct t2 {
auto operator()() {
printf("hi from non-local type\n");
return 1;
}
auto func() {
printf("hi from non-local named func\n");
return 1;
}
};
int main() {
auto f = []() {
printf("hi from lambda\n");
return 1;
};
struct t1 {
auto operator()() {
printf("hi from local type\n");
return 1;
}
};
f();
g();
t1 v1;
v1();
t2 v2;
v2();
v2.func();
}
$ lldb ./a.out
(lldb) p f()
hi from lambda
(int) $0 = 1
(lldb) p g()
hi from non-local lambda
(int) $1 = 1
(lldb) p v1()
hi from local type
(lldb) p v2()
hi from non-local type
(lldb) p v2.func()
hi from non-local named func
(lldb) p auto x = f()
hi from lambda
(lldb) p auto x = g()
hi from non-local lambda
(lldb) p auto x = v1()
error: expression failed to parse:
error: <user expression 7>:1:6: variable has incomplete type 'void'
auto x = v1()
^
(lldb) p auto x = v2()
error: expression failed to parse:
error: <user expression 8>:1:6: variable has incomplete type 'void'
auto x = v2()
^
(lldb) p auto x = v2.func()
error: expression failed to parse:
error: <user expression 9>:1:6: variable has incomplete type 'void'
auto x = v2.func()
^
(but a standalone auto function doesn't have the problem... because we don't produce declarations for those functions (even in a namespace, we just define them in the namespace)
So I think this is a problem with lldb's handling of auto return in general - not with lambdas in particular.
And I still have two related questions
1. Why is Clang being changed here, rather than fixing lldb to handle correct DWARF?
2. Alternatively: why are we emitting 'auto' return types at all (see previous comments/discussion) instead of treating these functions the same way we do for member function templates - omit them entirely (don't even emit declarations) if the return type isn't known.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D123319/new/
https://reviews.llvm.org/D123319
More information about the cfe-commits
mailing list