You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[clang] Fix crash when declaring invalid lambda member (#74110)
In valid code, there should only be a very specific set of members in a
lambda definition. If the user tries to define something inside the
lambda class, this assumption is violated and causes an assertion error.
This can be fixed by checking whether the members are valid, and if not,
ignore that the class members are potentially unexpected.
I've come across this while working on implementing lambdas in C++03.
auto y = [](auto &v) -> void { v.n = 0; };// cxx11-error {{'auto' not allowed in lambda parameter}} cxx11-note {{candidate function not viable}} cxx11-note {{conversion candidate}}
friendautoT::operator()(int) const;// cxx11-error {{'auto' return without trailing return type; deduced return types are a C++14 extension}}
628
630
friend T::operatorExpectedTypeT() const;
629
631
630
632
template<typename T>
631
-
friendvoidU::operator()(T&) const;
633
+
friendvoidU::operator()(T&) const;// cxx11-error {{friend declaration of 'operator()' does not match any declaration}}
632
634
// FIXME: This should not match, as above.
633
635
template<typename T>
634
-
friend U::operator ExpectedTypeU<T>() const;
636
+
friend U::operator ExpectedTypeU<T>() const;// cxx11-error {{friend declaration of 'operator void (*)(type-parameter-0-0 &)' does not match any declaration}}
635
637
#endif
636
638
637
639
private:
638
640
int n;
639
641
};
640
642
641
-
// Should be OK: lambda's call operator is a friend.
642
-
voiduse(X &x) { y(x); }
643
+
// Should be OK in C++14 and later: lambda's call operator is a friend.
644
+
voiduse(X &x) { y(x); }// cxx11-error {{no matching function for call to object}}
643
645
644
646
// This used to crash in return type deduction for the conversion opreator.
645
647
structA { int n; voidf() { +[](decltype(n)) {}; } };
0 commit comments