Skip to content

long double constructors not marked as const-incompatible #829

@VorpalBlade

Description

@VorpalBlade

Given:

#define _GNU_SOURCE
#include <stdio.h>
#include <math.h>

#define _PI_180 (M_PIl / 180.0)
#define _180_PI (180.0 / M_PIl)

int main(void) {
    printf("%LF\n", _PI_180);
    printf("%LF\n", _180_PI);
    return 0;
}

The generated code (with --translate-const-macros) is:

#![allow(dead_code, mutable_transmutes, non_camel_case_types, non_snake_case, non_upper_case_globals, unused_assignments, unused_mut)]
use ::c2rust_out::*;
extern "C" {
    fn printf(_: *const libc::c_char, _: ...) -> libc::c_int;
}
pub const M_PIl: f128::f128 = f128::f128::new(3.141592653589793238462643383279502884);
pub const _PI_180: f128::f128 = M_PIl / f128::f128::new(180.0f64);
pub const _180_PI: f128::f128 = f128::f128::new(180.0f64) / M_PIl;
unsafe fn main_0() -> libc::c_int {
    printf(b"%LF\n\0" as *const u8 as *const libc::c_char, _PI_180);
    printf(b"%LF\n\0" as *const u8 as *const libc::c_char, _180_PI);
    return 0 as libc::c_int;
}
pub fn main() {
    unsafe { ::std::process::exit(main_0() as i32) }
}

This does not compile, I have abbreviated the output as it just repeats of the same things (several times):

error[E0015]: cannot call non-const fn `f128::new::<f64>` in constants
error[E0015]: cannot call non-const operator in constants

Software versions:

  • Arch Linux (rolling release distro).
  • glibc 2.37-2
  • clang 15.0.7-1
  • rustc 1.67.1 (from rustup)
  • c2rust 0.17.0 (from cargo install)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions