Boaz Brickner
88dac35ae8
Add support for C++ member operators (#6112)
Call `Sema::AddMemberOperatorCandidates()` to properly add candidates.
For C++ member operator calls, use the first arg as self.
C++ Interop Demo:
```c++
// my_number.h
class MyNumber {
public:
explicit MyNumber(int value) : value_(value) {}
int value() const { return value_; }
auto operator++() -> MyNumber;
private:
int value_;
};
```
```c++
// my_number.cpp
#include "my_number.h"
auto MyNumber::operator++() -> MyNumber {
++value_;
return *this;;
}
```
```carbon
// main.carbon
library "Main";
import Core library "io";
import Cpp library "my_number.h";
fn Run() -> i32 {
var num: Cpp.MyNumber = Cpp.MyNumber.MyNumber(14);
Core.Print(num.value());
++num;
Core.Print(num.value());
return 0;
}
```
```shell
$ clang -c my_number.cpp
$ bazel-bin/toolchain/carbon compile main.carbon
$ bazel-bin/toolchain/carbon link my_number.o main.o --output=demo
$ ./demo
14
15
```
Part of https://github.com/carbon-language/carbon-lang/issues/5995.
2025-09-24 10:11:09 +00:00
..
2025-09-24 10:11:09 +00:00
2025-02-20 22:42:47 +00:00
2025-09-24 10:11:09 +00:00
2025-04-15 22:40:29 +00:00
2025-04-11 21:47:43 +00:00
2025-09-19 20:22:47 +00:00
2025-09-24 10:11:09 +00:00
2024-09-05 23:39:58 +00:00
2025-01-27 23:48:44 +00:00
2025-09-17 09:31:36 +00:00
2025-09-08 16:15:10 +00:00
2025-09-17 09:31:36 +00:00
2025-09-08 16:15:10 +00:00
2025-09-18 13:04:18 +00:00
2025-07-11 22:29:10 +00:00
2025-09-08 16:15:10 +00:00
2025-09-22 19:11:06 +00:00
2025-07-10 21:21:19 +00:00
2025-07-10 16:32:39 +00:00
2025-09-23 22:11:11 +00:00
2025-08-28 23:00:53 +00:00
2025-04-23 15:20:18 +00:00
2025-05-07 22:20:39 +00:00
2025-05-07 22:20:39 +00:00
2025-09-23 21:00:54 +00:00
2025-06-03 18:07:23 +00:00
2025-06-10 22:09:31 +00:00
2025-06-10 22:09:31 +00:00
2025-08-12 22:08:07 +00:00
2025-07-21 20:02:27 +00:00
2025-09-10 13:47:59 +00:00
2025-06-12 20:37:27 +00:00
2025-09-23 22:11:11 +00:00
2025-05-29 19:48:16 +00:00
2025-09-23 17:51:31 +00:00
2025-04-14 14:28:15 +00:00
2025-09-15 17:03:43 +00:00
2025-08-12 16:27:07 +00:00
2025-03-04 21:01:59 +00:00
2025-08-21 21:41:53 +00:00
2025-06-10 22:09:31 +00:00
2025-05-01 20:24:15 +00:00
2025-05-01 20:24:15 +00:00
2025-09-12 22:59:37 +00:00
2025-09-12 18:04:10 +00:00
2025-03-18 23:49:24 +00:00
2024-07-03 17:49:47 +00:00
2025-04-17 21:58:37 +00:00
2025-04-28 19:06:24 +00:00
2025-09-10 17:57:08 +00:00
2024-12-02 18:51:44 +00:00
2025-06-03 18:07:23 +00:00
2025-08-04 19:39:22 +00:00
2025-04-23 19:03:53 +00:00
2025-04-28 19:06:24 +00:00
2025-05-09 16:35:28 +00:00
2024-07-12 22:38:06 +00:00
2025-09-12 23:27:02 +00:00
2025-04-23 19:03:53 +00:00
2025-02-14 19:44:36 +00:00
2025-07-25 18:34:07 +00:00
2025-08-05 23:03:32 +00:00
2025-06-02 19:16:31 +00:00
2025-05-01 20:24:15 +00:00
2025-09-02 23:15:26 +00:00
2025-09-16 20:45:01 +00:00
2025-06-25 23:45:14 +00:00
2024-07-12 22:38:06 +00:00
2025-04-23 15:20:18 +00:00
2025-06-10 20:54:58 +00:00
2024-07-12 22:38:06 +00:00
2025-04-28 19:06:24 +00:00
2024-12-18 00:19:12 +00:00
2025-08-28 23:00:53 +00:00
2024-07-12 22:38:06 +00:00
2025-09-02 23:15:26 +00:00
2024-07-12 22:38:06 +00:00
2025-04-23 19:03:53 +00:00
2025-04-10 20:53:42 +00:00
2025-08-12 16:27:07 +00:00
2025-06-10 22:09:31 +00:00
2025-09-18 22:10:50 +00:00
2025-05-10 17:36:28 +00:00
2025-07-30 20:24:38 +00:00
2025-05-22 18:58:47 +00:00
2025-07-25 18:34:07 +00:00
2025-07-25 18:34:07 +00:00
2025-08-12 00:10:43 +00:00
2025-09-18 22:10:50 +00:00
2025-09-17 17:27:52 +00:00
2025-09-10 21:40:27 +00:00
2025-07-25 21:09:24 +00:00
2025-07-25 21:09:24 +00:00
2025-03-21 23:09:37 +00:00
2025-04-29 18:00:07 +00:00
2025-09-12 18:04:10 +00:00
2025-07-10 18:27:28 +00:00
2025-04-28 19:06:24 +00:00
2025-04-14 14:28:15 +00:00
2025-09-12 22:59:37 +00:00
2025-09-12 23:27:02 +00:00
2025-07-09 22:42:27 +00:00
2025-08-29 01:11:24 +00:00
2025-08-29 01:11:24 +00:00
2025-09-23 17:51:31 +00:00
2025-05-01 20:24:15 +00:00
2025-05-19 22:50:16 +00:00
2025-04-14 14:28:15 +00:00
2025-04-28 19:06:24 +00:00
2024-10-17 22:47:40 +00:00
2025-03-18 00:31:17 +00:00
2025-01-22 23:15:00 +00:00
2025-09-17 09:31:36 +00:00
2025-04-28 19:06:24 +00:00
2025-06-10 20:54:58 +00:00
2025-06-10 20:54:58 +00:00
2025-06-10 22:09:31 +00:00
2025-06-10 22:09:31 +00:00
2025-02-07 22:35:18 +00:00
2025-09-02 23:15:26 +00:00
2025-09-19 16:42:46 +00:00
2025-02-26 18:44:36 +00:00
2025-02-25 02:07:43 +00:00
2025-09-04 19:19:59 +00:00
2025-01-23 02:21:48 +00:00
2025-08-04 19:39:22 +00:00
2025-08-04 19:39:22 +00:00
2025-09-15 23:59:00 +00:00
2025-05-01 22:17:55 +00:00
2025-05-01 22:17:55 +00:00
2025-04-14 14:28:15 +00:00
2025-09-12 00:13:33 +00:00
2025-05-01 22:17:55 +00:00
2025-03-01 08:00:17 +00:00
2025-05-07 22:20:39 +00:00
2025-05-07 22:20:39 +00:00
2025-09-15 17:03:43 +00:00
2025-07-30 14:34:24 +00:00
2025-09-23 17:51:31 +00:00
2025-06-11 21:34:01 +00:00
2025-09-17 09:31:36 +00:00
2025-04-14 14:28:15 +00:00
2025-09-16 20:44:39 +00:00
2025-09-16 20:44:39 +00:00
2025-09-15 12:29:49 +00:00
2025-09-15 12:29:49 +00:00