Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

float32(Inf) + friends gives codegen errors with nim cpp #18025

Open
timotheecour opened this issue May 16, 2021 · 1 comment
Open

float32(Inf) + friends gives codegen errors with nim cpp #18025

timotheecour opened this issue May 16, 2021 · 1 comment

Comments

@timotheecour
Copy link
Member

Example

when true:
  proc main()=
    let a1 = [NaN, Inf]
    let a2 = float32(Inf)
    let a3 = [float32(NaN), float32(NaN)]
    # let a2 = [float32(NaN), float32(Inf)]
    # let b = (1.0'f32 / 0.0'f32, )

    let val = float32(Inf)
    let b = [val, val]

    const val2 = float32(Inf)
    let b2 = [val2, val2] # BUG with nim cpp
      # c: ok
      # cpp: bug:
      # error: non-constant-expression cannot be narrowed from type 'double' to 'NF32' (aka 'float') in initializer list [-Wc++11-narrowing]

    # let b3 = [float32(Inf), float32(Inf)] # ditto

    # let b4 = [float32(1.0'f32 / 0.0'f32)] # ditto
    # let b5 = (float32(1.0'f32 / 0.0'f32),) # ditto
  main()

Current Output

/@mt12274.nim.cpp:52:86: error: non-constant-expression cannot be narrowed from type 'double' to 'NF32' (aka 'float') in initializer list [-Wc++11-narrowing]
static NIM_CONST tyArray__4YxcnnI8do9a6vmNKtzdSKw TM__WkvCQIn9ahz9cNeh9cQ2UK5gA_4 = {INF,
                                                                                     ^~~
/Users/timothee/git_clone/nim/Nim_devel/lib/nimbase.h:506:17: note: expanded from macro 'INF'
#    define INF (1.0 / 0.0)
                ^~~~~~~~~~~
/Users/timothee/git_clone/nim/timn/build/nimcache/@mt12274.nim.cpp:52:86: note: insert an explicit cast to silence this issue
static NIM_CONST tyArray__4YxcnnI8do9a6vmNKtzdSKw TM__WkvCQIn9ahz9cNeh9cQ2UK5gA_4 = {INF,
                                                                                     ^~~
                                                                                     static_cast<NF32>( )
/Users/timothee/git_clone/nim/Nim_devel/lib/nimbase.h:506:17: note: expanded from macro 'INF'
#    define INF (1.0 / 0.0)
                ^~~~~~~~~~~
/Users/timothee/git_clone/nim/timn/build/nimcache/@mt12274.nim.cpp:53:1: error: non-constant-expression cannot be narrowed from type 'double' to 'NF32' (aka 'float') in initializer list [-Wc++11-narrowing]
INF}
^~~
/Users/timothee/git_clone/nim/Nim_devel/lib/nimbase.h:506:17: note: expanded from macro 'INF'
#    define INF (1.0 / 0.0)
                ^~~~~~~~~~~
/Users/timothee/git_clone/nim/timn/build/nimcache/@mt12274.nim.cpp:53:1: note: insert an explicit cast to silence this issue
INF}
^~~
static_cast<NF32>( )
/Users/timothee/git_clone/nim/Nim_devel/lib/nimbase.h:506:17: note: expanded from macro 'INF'
#    define INF (1.0 / 0.0)

Expected Output

works

Additional Information

1.5.1 97970d9

@ringabout
Copy link
Member

ringabout commented Jun 3, 2021

I cannot reproduce the cpp codegen errors on windows.

when true:
  proc main()=
    let a1 = [NaN, Inf]
    let a2 = float32(Inf)
    let a3 = [float32(NaN), float32(NaN)]
    # let a2 = [float32(NaN), float32(Inf)]
    # let b = (1.0'f32 / 0.0'f32, )

    let val = float32(Inf)
    let b = [val, val]

    const val2 = float32(Inf)
    let b2 = [val2, val2] # BUG with nim cpp
      # c: ok
      # cpp: bug:
      # error: non-constant-expression cannot be narrowed from type 'double' to 'NF32' (aka 'float') in initializer list [-Wc++11-narrowing]

    let b3 = [float32(Inf), float32(Inf)] # ditto

    let b4 = [float32(1.0'f32 / 0.0'f32)] # ditto
    let b5 = (float32(1.0'f32 / 0.0'f32),) # ditto

    echo b2
    echo b3
    echo b4
    echo b5
  main()

with command nim cpp -r test.nim

[inf, inf]
[inf, inf]
[inf]
(inf,)

gcc info

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=D:/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/9.2.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-git-9.2.0/configure --build=x86_64-w64-mingw32 --enable-targets=all --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-libgomp --enable-lto --enable-graphite --enable-cxx-flags=-DWINPTHREAD_STATIC --disable-build-with-cxx --disable-build-poststage1-with-cxx --enable-libstdcxx-debug --enable-threads=posix --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libstdcxx-threads --enable-libstdcxx-time --with-gnu-ld --disable-werror --disable-nls --disable-win32-registry --enable-large-address-aware --disable-rpath --disable-symvers --prefix=/mingw64tdm --with-local-prefix=/mingw64tdm --with-pkgversion=tdm64-1 --with-bugurl=http://tdm-gcc.tdragon.net/bugs
Thread model: posix
gcc version 9.2.0 (tdm64-1)

Nim version

Nim Compiler Version 1.5.1 [Windows: amd64]
Compiled at 2021-06-02
Copyright (c) 2006-2021 by Andreas Rumpf

and Nim 1.4.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants