Search code examples
c++g++stdc++17greatest-common-divisor

std::gcd does not compile in g++ 5.4.0 -- 'gcd' is not a member of 'std'


Environment:

  • Ubuntu 16.04 64 bit
  • g++ version 5.4.0

This is the code:

#include <numeric>
...
auto g = std::gcd(10, 4);
...

I have turned on the -std=c++17 option in the compiling command:

g++ -m64 -std=c++17   -c -g -w -MMD -MP -MF "build/Debug/GNU-Linux/main.o.d" -o build/Debug/GNU-Linux/main.o main.cpp

Then I got the error:

error: 'gcd' is not a member of 'std'

From this webpage, std::gcd is introduced since C++17.

From this webpage, my version of g++ supports C++17.

But why is there still an error? The same code compiles without any error in Visual Studio 2017.


Solution

  • std::gcd is available from GCC 7.1 onwards only.

    From Table 1.5. C++ 2017 Implementation Status

    enter image description here

    See conformance viewer for multiple GCC versions.