-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang] [Sema] Fix a crash when a friend
function is redefined as deleted
#135679
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -271,3 +271,33 @@ void operators() { | |
if (to_int_int) {} // expected-error {{attempt to use a deleted function: deleted (TO<int, int>, operator bool)}} | ||
static_cast<bool>(to_int_int); // expected-error {{static_cast from 'TO<int, int>' to 'bool' uses deleted function: deleted (TO<int, int>, operator bool)}} | ||
}; | ||
|
||
namespace gh135506 { | ||
struct a { | ||
// FIXME: We currently don't diagnose these invalid redeclarations if the | ||
// second declaration is defaulted or deleted. This probably needs to be | ||
// handled in ParseCXXInlineMethodDef() after parsing the defaulted/deleted | ||
// body. | ||
friend consteval int f() { return 3; } | ||
friend consteval int f() = delete("foo"); | ||
|
||
friend consteval int g() { return 3; } | ||
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. We should also test |
||
friend consteval int g() = delete; | ||
|
||
friend int h() { return 3; } | ||
friend int h() = delete; | ||
|
||
friend consteval int i() = delete; // expected-note {{previous definition is here}} | ||
friend consteval int i() { return 3; } // expected-error {{redefinition of 'i'}} | ||
}; | ||
|
||
struct b { | ||
friend consteval bool operator==(b, b) { return true; } // expected-note {{previous declaration is here}} | ||
friend consteval bool operator==(b, b) = default; // expected-error {{defaulting this equality comparison operator is not allowed because it was already declared outside the class}} | ||
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. This diagnostic is a bit off, the previous declaration is not outside the class. 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. Oh, that’s not ideal either; I’ll make a separate issue for that (this pr doesn’t change anything about how that is handled; I just put it there to check that we don’t crash on it). 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. Actually... the wording in the standard around this is a bit unclear (obviously this is ill-formed but I’m talking about the case where the first declaration is not a definition). I’ll investigate this some more. |
||
}; | ||
|
||
struct c { | ||
friend consteval bool operator==(c, c) = default; // expected-note {{previous definition is here}} | ||
friend consteval bool operator==(c, c) { return true; } // expected-error {{redefinition of 'operator=='}} | ||
}; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.