c2z
c2z copied to clipboard
Lambda mangling test
Some lambda test - C++20: https://godbolt.org/z/Gq1h7Ezn9
Lambda 1
input
#include <iostream>
template<typename T> int print_hello = (std::cout << "hello\n", 0);
struct X {
// Should only print hello once, regardless of how many TUs this appears in.
static const intptr_t n = (print_hello<decltype([]{})>, 0);
};
output
error: unhandled `VarTemplateDecl`
error: unhandled `VarTemplateSpecializationDecl`
info: transpiled 214903/214939 (99.98 %)
info: formating `x86_64/linux/gnu/cxx.zig`
// auto generated by c2z
const std = @import("std");
//const cpp = @import("cpp");
pub const X = extern struct {
extern const _ZN1X1nE: isize;
pub inline fn n() isize {
return _ZN1X1nE;
}
};
Lambda 2
input
struct A {
int f(decltype([]{ static int n; return ++n; }) lambda = {}) {
return lambda();
}
};
int a = A().f(), b = A().f();
output
info: binding `cxx.h`
error: unknow type `decltype([] {
static int n;
return ++n;
})`, falling back to `*anyopaque`
error: unhandled `RecoveryExpr`
error: syntax errors in `A.f`
info: transpiled 56/58 (96.55 %)
info: formating `x86_64/linux/gnu/cxx.zig`
// auto generated by c2z
const std = @import("std");
//const cpp = @import("cpp");
pub const A = extern struct {
// syntax errors:
// pub fn f(self: *A, lambda: *anyopaque) c_int {
// return ();
// }
//
};
extern var a: c_int;
pub inline fn a() *c_int {
return &a;
}
extern var b: c_int;
pub inline fn b() *c_int {
return &b;
}
References
- https://github.com/itanium-cxx-abi/cxx-abi/issues/157#issuecomment-1611955848
- https://github.com/itanium-cxx-abi/cxx-abi/issues/31#issuecomment-529712699