Search code examples
c++gccstdubuntu-18.04std-byte

std::byte is not member of 'std'


I'm trying to learn new features/gimmicks of c++17, but then I got to std::byte and for some unknown reason I can't seem to be able to compile even most basic "hello world" type program with the type.

entire program:

#include <cstddef>
int main(int argc, char* argv[])
{
    std::byte byte;
    return 0;
}

compilation command:

g++ ./main.cpp

But the output is always:

./main.cpp: In function ‘int main(int, char**)’:
./main.cpp:4:10: error: ‘byte’ is not a member of ‘std’
    std::byte byte;

I work on Ubuntu 18.04 with gcc 7.4.0. I have checked "/usr/include/c++/7.4.0/" and header file cstddef is there and byte seems to be defined.

I have also tried to use clang:

clang++ ./main.cpp

But the result was same. At this point I can only think that cstddef is corrupted/bugged. Are there any solutions to this?


Solution

  • As πάντα ῥεῖ pointed out in comment I was missing c++17 compile flag. Right compilation command:

    g++ -std=c++17 ./main.cpp