zig icon indicating copy to clipboard operation
zig copied to clipboard

zig c++: Fails to find std::views::chunk from <ranges> with -std=c++23

Open thng292 opened this issue 1 month ago • 5 comments

Zig Version

0.15.2

Steps to Reproduce and Observed Behavior

$ echo -e "#include <ranges>\nauto ints = {0,1,2,3}; auto tmp = ints | std::views::chunk(2);" > chunk.cpp

$ g++ chunk.cpp -std=c++23 -c # No error
$ clang++ chunk.cpp -std=c++23 -c # No error

$ zig c++ chunk.cpp -std=c++23 -c
chunk.cpp:2:54: error: no member named 'chunk' in namespace 'std::ranges::views'
    2 | auto ints = {0,1,2,3}; auto tmp = ints | std::views::chunk(2);
      |                                          ~~~~~~~~~~~~^
1 error generated.

Expected Behavior

The file should compile

thng292 avatar Nov 08 '25 11:11 thng292

Which Clang version are you testing with?

alexrp avatar Nov 08 '25 11:11 alexrp

clang --version
Ubuntu clang version 18.1.3 (1ubuntu1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

I run all the commands in docker.io/nvidia/cuda:13.0.1-cudnn-devel-ubuntu24.04 container.

thng292 avatar Nov 08 '25 11:11 thng292

just looks like a libc++ issue

~ $ clang++ -v
clang version 21.1.0 (https://github.com/llvm/llvm-project 3623fe661ae35c6c80ac221f14d85be76aa870f1)
~ $ clang++ chunk.cpp -std=c++23 -c -stdlib=libstdc++
~ $ clang++ chunk.cpp -std=c++23 -c -stdlib=libc++
chunk.cpp:2:54: error: no member named 'chunk' in namespace 'std::ranges::views'
    2 | auto ints = {0,1,2,3}; auto tmp = ints | std::views::chunk(2);
      |                                                      ^~~~~
1 error generated.

xdBronch avatar Nov 08 '25 11:11 xdBronch

Is there any workaround, I tried zig c++ with -stdlib=libstdc++ but it does not work.

$ zig c++ chunk.cpp -std=c++23 -c -stdlib=libc++   
zig: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]
chunk.cpp:2:54: error: no member named 'chunk' in namespace 'std::ranges::views'
    2 | auto ints = {0,1,2,3}; auto tmp = ints | std::views::chunk(2);
      |                                          ~~~~~~~~~~~~^
1 error generated.

thng292 avatar Nov 08 '25 13:11 thng292

There is an upstream issue about implementing views::chunk https://github.com/llvm/llvm-project/issues/105187

LinuxUserGD avatar Nov 08 '25 20:11 LinuxUserGD