Skip to content
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

[LLD][COFF] Mark operator== const to avoid ambiguity in C++20. #68119

Merged
merged 1 commit into from
Oct 4, 2023

Conversation

bazuzi
Copy link
Contributor

@bazuzi bazuzi commented Oct 3, 2023

C++20 will automatically generate an operator== with reversed operand order, which is ambiguous with the written operator== when one argument is marked const and the other isn't.

C++20 will automatically generate an operator== with reversed operand order, which is ambiguous with the written operator== when one argument is marked const and the other isn't.
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 3, 2023

@llvm/pr-subscribers-platform-windows

@llvm/pr-subscribers-lld

Changes

C++20 will automatically generate an operator== with reversed operand order, which is ambiguous with the written operator== when one argument is marked const and the other isn't.


Full diff: https://github.com/llvm/llvm-project/pull/68119.diff

1 Files Affected:

  • (modified) lld/COFF/Config.h (+1-1)
diff --git a/lld/COFF/Config.h b/lld/COFF/Config.h
index e66ab3a32c56721..ff87eab2744dd51 100644
--- a/lld/COFF/Config.h
+++ b/lld/COFF/Config.h
@@ -72,7 +72,7 @@ struct Export {
   StringRef symbolName;
   StringRef exportName; // Name in DLL
 
-  bool operator==(const Export &e) {
+  bool operator==(const Export &e) const {
     return (name == e.name && extName == e.extName &&
             aliasTarget == e.aliasTarget &&
             ordinal == e.ordinal && noname == e.noname &&

@bazuzi
Copy link
Contributor Author

bazuzi commented Oct 3, 2023

@mstorsjo I don't have write access, so can't specifically add reviewers, but I see that you reviewed the last change touching this file. Would you be able to take a look at this small change?

@aganea
Copy link
Member

aganea commented Oct 3, 2023

C++20 will automatically generate an operator== with reversed operand order, which is ambiguous with the written operator== when one argument is marked const and the other isn't.

You mean when building LLD with cmake ... -DCMAKE_CXX_STANDARD=20?

Copy link
Member

@aganea aganea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reproduced the issue, thanks for the fix! LGTM. I can merge the change if there are no further objections from @mstorsjo

@aganea aganea changed the title Mark operator== const to avoid ambiguity in C++20. [LLD] Mark operator== const to avoid ambiguity in C++20. Oct 4, 2023
@aganea aganea changed the title [LLD] Mark operator== const to avoid ambiguity in C++20. [LLD][COFF] Mark operator== const to avoid ambiguity in C++20. Oct 4, 2023
@bazuzi
Copy link
Contributor Author

bazuzi commented Oct 4, 2023

Thanks!

@mstorsjo
Copy link
Member

mstorsjo commented Oct 4, 2023

I reproduced the issue, thanks for the fix! LGTM. I can merge the change if there are no further objections from @mstorsjo

No objection from me, this seems straightforward to me. Thanks for the patch, and thanks for reviewing it!

@aganea aganea merged commit 8899b71 into llvm:main Oct 4, 2023
6 checks passed
@bazuzi bazuzi deleted the const branch November 30, 2023 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants