-
Notifications
You must be signed in to change notification settings - Fork 15.9k
[APINotes] Support overloaded operators #177382
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
Conversation
This adds support for annotating C++ operators via API Notes. For instance:
```
Tags:
- Name: MyTag
Methods:
- Name: operator+
Availability: none
```
rdar://148534260
|
@llvm/pr-subscribers-clang Author: Egor Zhdan (egorzhdan) ChangesThis adds support for annotating C++ operators via API Notes. For instance: rdar://148534260 Full diff: https://github.com/llvm/llvm-project/pull/177382.diff 4 Files Affected:
|
Xazax-hun
left a comment
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.
The changes look good to me. I am a bit worried about the people misusing this though as operators in a namespace would apply to a potentially huge number of overloads.
|
@Xazax-hun this only applies to operators that are declared as methods, so this wouldn't apply to operators in a namespace. |
| std::string MethodName; | ||
| if (CXXMethod->isOverloadedOperator()) | ||
| MethodName = | ||
| std::string("operator") + | ||
| getOperatorSpelling(CXXMethod->getOverloadedOperator()); | ||
| else | ||
| MethodName = CXXMethod->getName(); |
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.
Personally, I find that a ternary is easier to read:
| std::string MethodName; | |
| if (CXXMethod->isOverloadedOperator()) | |
| MethodName = | |
| std::string("operator") + | |
| getOperatorSpelling(CXXMethod->getOverloadedOperator()); | |
| else | |
| MethodName = CXXMethod->getName(); | |
| std::string MethodName = CXXMethod->isOverloadedOperator() | |
| ? std::string("operator") + | |
| getOperatorSpelling(CXXMethod->getOverloadedOperator()) | |
| : CXXMethod->getName(); |
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.
I initially wrote something similar, but got confused about this expression after using clang-format, so I replaced it with if-else to make it slightly more clear.
This makes sense, thanks! Can you update the description of the PR with this info? |
Done! |
This adds support for annotating C++ operators via API Notes. For instance:
At the moment only operators that are declared as methods of C++ records can be annotated.
rdar://148534260