Commit 109e39c
authored
Add support for nullptr literals in macros (carbon-language#6426)
Adding support for macros that evaluate to nullptr literal.
Demo:
```c++
// macros.h
void foo(int a[2]);
#define MyNullPtr nullptr
```
```c++
// macros.cpp
void foo(int a[2]) {
if (!a) {
printf("array a is nullptr\n");
return;
}
printf("a[0] = %d \n", a[0]);
}
```
```c++
// main.carbon
library "Main";
import Cpp library "macros.h";
fn Run() -> i32 {
Cpp.foo(Cpp.MyNullPtr);
return 0;
}
```
```
$ clang -c macros.cpp;
$ bazel-bin/toolchain/carbon compile main.carbon
$ bazel-bin/toolchain/carbon link macros.o main.o \--output=demo_carbon
$ ./demo_carbon
array a is nullptr
```
Part of carbon-language#63031 parent 62cb185 commit 109e39c
File tree
3 files changed
+21
-2
lines changed- toolchain/check
- cpp
- testdata/interop/cpp
3 files changed
+21
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2264 | 2264 | | |
2265 | 2265 | | |
2266 | 2266 | | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
2267 | 2271 | | |
2268 | 2272 | | |
2269 | 2273 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
| 66 | + | |
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
595 | 595 | | |
596 | 596 | | |
597 | 597 | | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
598 | 612 | | |
599 | 613 | | |
600 | 614 | | |
| |||
0 commit comments