Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cpp2rust/converter/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2599,6 +2599,14 @@ bool Converter::VisitUnaryExprOrTypeTraitExpr(
return false;
}

bool Converter::VisitTypeTraitExpr(clang::TypeTraitExpr *expr) {
clang::Expr::EvalResult result;
ENSURE(expr->EvaluateAsInt(result, ctx_));
StrCat(std::to_string(result.Val.getInt().getExtValue()));
computed_expr_type_ = ComputedExprType::FreshValue;
return false;
}

bool Converter::VisitEnumDecl(clang::EnumDecl *decl) {
ENSURE(decl_ids_.insert(GetID(decl)).second);
if (Mapper::Contains(ctx_.getCanonicalTagType(decl))) {
Expand Down
2 changes: 2 additions & 0 deletions cpp2rust/converter/converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
virtual bool
VisitUnaryExprOrTypeTraitExpr(clang::UnaryExprOrTypeTraitExpr *expr);

virtual bool VisitTypeTraitExpr(clang::TypeTraitExpr *expr);

virtual bool VisitEnumDecl(clang::EnumDecl *decl);

virtual bool VisitCXXDefaultArgExpr(clang::CXXDefaultArgExpr *expr);
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/builtin_types_compatible.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <assert.h>

int main(void) {
assert(__builtin_types_compatible_p(int, int) == 1);
assert(__builtin_types_compatible_p(int, long) == 0);

int x = 0;
assert(__builtin_types_compatible_p(__typeof__(x), int) == 1);
assert(__builtin_types_compatible_p(__typeof__(x), long) == 0);

int *p = 0;
assert(__builtin_types_compatible_p(__typeof__(p), int *) == 1);
assert(__builtin_types_compatible_p(__typeof__(p), long *) == 0);

unsigned long ul = 0;
assert(__builtin_types_compatible_p(__typeof__(ul), unsigned long) == 1);
assert(__builtin_types_compatible_p(__typeof__(ul), signed long) == 0);

return 0;
}
25 changes: 25 additions & 0 deletions tests/unit/out/refcount/builtin_types_compatible.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
extern crate libcc2rs;
use libcc2rs::*;
use std::cell::RefCell;
use std::collections::BTreeMap;
use std::io::prelude::*;
use std::io::{Read, Seek, Write};
use std::os::fd::AsFd;
use std::rc::{Rc, Weak};
pub fn main() {
std::process::exit(main_0());
}
fn main_0() -> i32 {
assert!((1 == 1));
assert!((0 == 0));
let x: Value<i32> = Rc::new(RefCell::new(0));
assert!((1 == 1));
assert!((0 == 0));
let p: Value<Ptr<i32>> = Rc::new(RefCell::new(Default::default()));
assert!((1 == 1));
assert!((0 == 0));
let ul: Value<u64> = Rc::new(RefCell::new(0_u64));
assert!((1 == 1));
assert!((0 == 0));
return 0;
}
27 changes: 27 additions & 0 deletions tests/unit/out/unsafe/builtin_types_compatible.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extern crate libc;
use libc::*;
extern crate libcc2rs;
use libcc2rs::*;
use std::collections::BTreeMap;
use std::io::{Read, Seek, Write};
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
use std::rc::Rc;
pub fn main() {
unsafe {
std::process::exit(main_0() as i32);
}
}
unsafe fn main_0() -> i32 {
assert!(((1) == (1)));
assert!(((0) == (0)));
let mut x: i32 = 0;
assert!(((1) == (1)));
assert!(((0) == (0)));
let mut p: *mut i32 = Default::default();
assert!(((1) == (1)));
assert!(((0) == (0)));
let mut ul: u64 = 0_u64;
assert!(((1) == (1)));
assert!(((0) == (0)));
return 0;
}
Loading