diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 59943ad2..25814b7a 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -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))) { diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 8e2fda4c..9ee8a2d9 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -282,6 +282,8 @@ class Converter : public clang::RecursiveASTVisitor { virtual bool VisitUnaryExprOrTypeTraitExpr(clang::UnaryExprOrTypeTraitExpr *expr); + virtual bool VisitTypeTraitExpr(clang::TypeTraitExpr *expr); + virtual bool VisitEnumDecl(clang::EnumDecl *decl); virtual bool VisitCXXDefaultArgExpr(clang::CXXDefaultArgExpr *expr); diff --git a/tests/unit/builtin_types_compatible.c b/tests/unit/builtin_types_compatible.c new file mode 100644 index 00000000..85e0a0e7 --- /dev/null +++ b/tests/unit/builtin_types_compatible.c @@ -0,0 +1,20 @@ +#include + +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; +} diff --git a/tests/unit/out/refcount/builtin_types_compatible.rs b/tests/unit/out/refcount/builtin_types_compatible.rs new file mode 100644 index 00000000..1509d9c7 --- /dev/null +++ b/tests/unit/out/refcount/builtin_types_compatible.rs @@ -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 = Rc::new(RefCell::new(0)); + assert!((1 == 1)); + assert!((0 == 0)); + let p: Value> = Rc::new(RefCell::new(Default::default())); + assert!((1 == 1)); + assert!((0 == 0)); + let ul: Value = Rc::new(RefCell::new(0_u64)); + assert!((1 == 1)); + assert!((0 == 0)); + return 0; +} diff --git a/tests/unit/out/unsafe/builtin_types_compatible.rs b/tests/unit/out/unsafe/builtin_types_compatible.rs new file mode 100644 index 00000000..085dbec3 --- /dev/null +++ b/tests/unit/out/unsafe/builtin_types_compatible.rs @@ -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; +}