0

I'm trying to compile a minimal viable example, which contains the following file:
main.cpp:

#include <expected>
#include <iostream>

std::expected<int, std::string> try_func() {
    return 100;
}

int main() {
    try_func();

    return 0;
}

I'm additionally using premake5 to create my build scripts. Here is my build script: premake5.lua:

workspace "interop"
    configurations { "Release" }
    architecture "x64"
    startproject "test_project"

project "test_project" 
    kind "ConsoleApp"
    language "C++"
    cppdialect "C++latest"

    location "test_project"

    targetdir ("bin/%{cfg.buildcfg}/%{prj.name}")
    objdir ("bin-int/%{cfg.buildcfg}/%{prj.name}")

    files
    {
        "test_project/main.cpp"
    }

The project is structured as follows:

interop
  test_project
    main.cpp
  premake5.lua

Compiling on Windows

To compile on Windows I just run:

premake5 vs2022

And then I build the generated VS projects, everything works correctly.

Compiling on Linux

To compile on Linux I run:

premake5 gmake
make 

My CXX is GCC, and I've updated to the latest version via -Syu. Running the above command produces the following warnings:

'expected' in namespace 'std' does not name a template type

Note that I do get the following message:

'std::expected' is only available from C++23 onwards

I'm however puzzled as to why I'm not supposedly compiling with C++23 when I'm using the latest flag. Any help is greatly appreciated.

  • 1
    Don't you think the answer is already given? Although the dupe is old, sort the answers by modified dates and you find a proper answer. C++23 is not released yet, why do you expect it to be default? – 273K Aug 10 '23 at 03:44
  • Notice that [`cppdialect`](https://premake.github.io/docs/cppdialect) doesn't support yet C++23. So you have to rely on [`buildoptions`](https://premake.github.io/docs/buildoptions). – Jarod42 Aug 10 '23 at 11:17

0 Answers0