GitHub Actions is not C++17 compliant

Sample repository: https://github.com/hayesall/CI-practice/


charconv is one of the C++ standard library headers in C++ 17. However, building a project that uses this header in GitHub Actions (e.g. with cmake and gcc-9) results in the error:

[ 50%] Building CXX object CMakeFiles/CIpractice.dir/project/example.cpp.o
/home/runner/work/CI-practice/CI-practice/project/example.cpp:5:10: fatal error: charconv: No such file or directory
 #include <charconv>
          ^~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/CIpractice.dir/project/example.cpp.o] Error 1
make[1]: *** [CMakeFiles/CIpractice.dir/all] Error 2
make: *** [all] Error 2

Is there a workaround for this, or are there plans to make GitHub Actions compliant with the standard?


GitHub Actions cmake.yml
name: CMake

on: [push]

env:
  # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
  BUILD_TYPE: Release
  CC: gcc-9

jobs:
  build:
    # The CMake configure and build commands are platform agnostic and should work equally
    # well on Windows or Mac.  You can convert this to a matrix build if you need
    # cross-platform coverage.
    # See: https://docs.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow#configuring-a-build-matrix
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - name: Create Build Environment
      # Some projects don't allow in-source building, so create a separate build directory
      # We'll use this as our working directory for all subsequent commands
      run: cmake -E make_directory ${{runner.workspace}}/build

    - name: Configure CMake
      # Use a bash shell so we can use the same syntax for environment variable
      # access regardless of the host operating system
      shell: bash
      working-directory: ${{runner.workspace}}/build
      # Note the current convention is to use the -S and -B options here to specify source
      # and build directories, but this is only available with CMake 3.13 and higher.
      # The CMake binaries on the Github Actions machines are (as of this writing) 3.12
      run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE

    - name: Build
      working-directory: ${{runner.workspace}}/build
      shell: bash
      # Execute the build.  You can specify a specific target with "--target <NAME>"
      run: cmake --build . --config $BUILD_TYPE

    - name: Test
      working-directory: ${{runner.workspace}}/build
      shell: bash
      # Execute tests defined by the CMake configuration.
      # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
      run: ctest -C $BUILD_TYPE
CMakeLists.txt
cmake_minimum_required(VERSION 3.12)

project(CIpractice)

add_executable(CIpractice project/example.cpp)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
project/example.cpp
// Example came out of:
// https://dzone.com/articles/how-to-use-the-newest-c-string-conversion-routines
// Tutorials are likely licensed in some way, but I did not check.

#include <charconv>
#include <string>
#include <iostream>

int main() {

  const std::string str1 { "123" };
  int value = 0;

  const auto res = std::from_chars(
    str1.data(),
    str1.data() + str1.size(),
    value
  );

  if (res.ec == std::errc()) {
    std::cout << "value: " << value << ", distance: " << res.ptr - str1.data() << '\n';
  } else if (res.ec == std::errc::invalid_argument) {
    std::cout << "invalid argument!\n";
  } else if (res.ec == std::errc::result_out_of_range) {
    std::cout << "out of range! res.ptr distance: " << res.ptr - str1.data() << '\n';
  }
}

This doesn’t seem directly related to Actions. Do you mean that the virtual environments used by GitHub hosted runners do not support this?

The floating point part of charconv is still only implemented by MSVC as far as I know, and on Linux you seem to need a minimum libstdc++ version (from 2017 though):

GCC 8.0 did have integer support back in 2018 on the other hand: https://www.bfilipek.com/2018/12/fromchars.html?m=1

According to the documentation on Software installed on GitHub-hosted runners the ubuntu-latest environment still uses Ubuntu 18.04, so I wouldn’t surprised if the compiler isn’t quite up to date there. :wink:

You could try installing a current compiler, or switching to the ubuntu-20.04 environment.

1 Like