c++c++20freebsdclang++libc++

Clang++16 cant find the sort() function from `std::ranges` on FreeBSD 13.2


I am trying to compile a program that uses std::ranges::sort() with clang++16. According to the website https://en.cppreference.com/w/cpp/compiler_support/20, The One Ranges Proposal was implemented in Clangs' libc++ version 13 (partial), 15 (requires -fexperimental-library flag), and 16 (without the flag).

I installed clang++16 with sudo pkg install llvm16, but when trying to compile the application it errors out with "no matching function for call to 'sort'".

Minimal reproducible example:

#include <algorithm>
#include <ranges>
#include <array>

int main()
{
    std::array s {5, 7, 4, 2, 8, 6, 1, 9, 0, 3};

    std::ranges::sort(s);
}

trying to compile with clang++16 -std=c++20 -stdlib=libc++ test.cpp -o test results in this error:

test.cpp:9:15: error: no type named 'sort' in namespace 'std::ranges'
        std::ranges::sort(s);
        ~~~~~~~~~~~~~^
1 error generated.

What am I doing wrong?


Solution

  • The version of libc++ supplied in the FreeBSD 13.2 image is too old. Using the -fexperimental-library flag doesn't help.

    I was able to successfully compile the example code with -fexperimental-library flag using the FreeBSD 14.0 image.