-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[clang] Fix crash when declaring invalid lambda member #74110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// RUN: %clang_cc1 -std=c++11 -Wno-unused-value -fsyntax-only -verify=expected,expected-cxx14,cxx11 -fblocks %s | ||
// RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify -verify=expected-cxx14 -fblocks %s | ||
// RUN: %clang_cc1 -std=c++17 -Wno-unused-value -verify -ast-dump -fblocks %s | FileCheck %s | ||
|
||
|
@@ -558,8 +559,8 @@ struct B { | |
int x; | ||
A a = [&] { int y = x; }; | ||
A b = [&] { [&] { [&] { int y = x; }; }; }; | ||
A d = [&](auto param) { int y = x; }; | ||
A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; }; | ||
A d = [&](auto param) { int y = x; }; // cxx11-error {{'auto' not allowed in lambda parameter}} | ||
A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; }; // cxx11-error 2 {{'auto' not allowed in lambda parameter}} | ||
}; | ||
|
||
B<int> b; | ||
|
@@ -589,6 +590,7 @@ struct S1 { | |
void foo1() { | ||
auto s0 = S1{[name=]() {}}; // expected-error 2 {{expected expression}} | ||
auto s1 = S1{[name=name]() {}}; // expected-error {{use of undeclared identifier 'name'; did you mean 'name1'?}} | ||
// cxx11-warning@-1 {{initialized lambda captures are a C++14 extension}} | ||
} | ||
} | ||
|
||
|
@@ -604,7 +606,7 @@ namespace PR25627_dont_odr_use_local_consts { | |
|
||
namespace ConversionOperatorDoesNotHaveDeducedReturnType { | ||
auto x = [](int){}; | ||
auto y = [](auto &v) -> void { v.n = 0; }; | ||
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}} | ||
using T = decltype(x); | ||
using U = decltype(y); | ||
using ExpectedTypeT = void (*)(int); | ||
|
@@ -624,22 +626,22 @@ namespace ConversionOperatorDoesNotHaveDeducedReturnType { | |
template<typename T> | ||
friend constexpr U::operator ExpectedTypeU<T>() const noexcept; | ||
#else | ||
friend auto T::operator()(int) const; | ||
friend auto T::operator()(int) const; // cxx11-error {{'auto' return without trailing return type; deduced return types are a C++14 extension}} | ||
friend T::operator ExpectedTypeT() const; | ||
|
||
template<typename T> | ||
friend void U::operator()(T&) const; | ||
friend void U::operator()(T&) const; // cxx11-error {{friend declaration of 'operator()' does not match any declaration}} | ||
// FIXME: This should not match, as above. | ||
template<typename T> | ||
friend U::operator ExpectedTypeU<T>() const; | ||
friend U::operator ExpectedTypeU<T>() const; // cxx11-error {{friend declaration of 'operator void (*)(type-parameter-0-0 &)' does not match any declaration}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oof, that's a bit of a gross diagnostic (not the fault of your patch). |
||
#endif | ||
|
||
private: | ||
int n; | ||
}; | ||
|
||
// Should be OK: lambda's call operator is a friend. | ||
void use(X &x) { y(x); } | ||
// Should be OK in C++14 and later: lambda's call operator is a friend. | ||
void use(X &x) { y(x); } // cxx11-error {{no matching function for call to object}} | ||
|
||
// This used to crash in return type deduction for the conversion opreator. | ||
struct A { int n; void f() { +[](decltype(n)) {}; } }; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move the isInvalidDecl check to declaresSameEntity?
I doubt this is the only place this might happen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I can tell nowhere is checking what they pass to
declaresSameEntity(...)
but I did not dig too deeply to see if we know they are valid earlier in some way.