C++

'std::gcd' Is Not a Member of 'std' Fix

std::gcd lives in one header, <numeric> - not in <cmath>, where a math function is expected, and not in <algorithm>. On this library version almost nothing rescues it by accident: in the sweep probed here, covering all 106 standard headers in the library's header set, only <execution> and <random> pull the name in on the side, and the textbook combination of <iostream> and <vector> does not. Like its sibling std::reduce, this error offers no note at all - no header is named, no include is suggested - so the fix has to come from knowing the name's home. This guide pins down the one failing shape, the two transitive rescues, and the one include that fixes the error by specification.

Written December 2, 2026 · Tested with GCC 13.3.0 · 22 min read

By the end of this guide
  • The error: the include is missing, in a lean file
  • The textbook version fails too - with no note to follow
  • Neighboring headers: 103 fail the same way, and two rescue it
  • The fix

Written December 2, 2026

Tested with GCC 13.3.0

What this guide is

std::gcd is a function template defined in the header <numeric>. It computes the greatest common divisor of two integers: if both arguments are zero it returns zero, and otherwise it returns the greatest common divisor of the absolute values of its arguments. Its two arguments may have different integer types, and the result has their common type. It has existed since C++17 and is constexpr from its introduction. A call whose arguments are not integer types - or are bool - is ill-formed, and the behavior is undefined if an argument's absolute value is not representable in the common type.

Because the template lives in one specific header, 'gcd' is not a member of 'std' has one common cause:

  • The #include <numeric> line is missing, and no other header in the file pulls the name in transitively. For this error, in the contexts probed here, GCC prints no suggestion tail on the error line, no help lines - and no note lines at all. That silence is shared with its sibling std::reduce and separates both from std::invoke, whose failing headers all carry a note naming the home header. The fix has to come from the name's home header, not from the diagnostic.

What makes this error worth separating from its relatives is where the name is expected to live. A greatest-common-divisor function reads like math, so the first header reached for is <cmath>, and the second is <algorithm> - and in the sweep probed here both fail, with the same bare error as every other failing header. The sweep covers every one of the 106 standard headers in this library's header set, compiled as the only header in the program, and the outcome splits only two ways - the one uniform failure, or a rescue - and the rescue set has exactly three entries: <numeric> itself, <execution>, and <random>. Its siblings in this family - std::reduce and std::invoke among them - have their own guides and are linked at the end, not re-taught here.

The error: the include is missing, in a lean file

This program returns success if the greatest common divisor of 12 and 18 is 6, but includes only <limits>:

C++
#include <limits>
int main() {
    return std::gcd(12, 18) == 6 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 a_limits.cpp -o a_limits_prog
a_limits.cpp: In function 'int main()':
a_limits.cpp:3:17: error: 'gcd' is not a member of 'std'
    3 |     return std::gcd(12, 18) == 6 ? 0 : 1;
      |                 ^~~

That is the whole output: one plain error line, and nothing after it. No suggestion tail rides on the error line itself, there are no note lines, and there are no help lines. The same program with no include at all fails the same way, just as bare:

C++
int main() {
    return std::gcd(12, 18) == 6 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 n_none.cpp -o n_none_prog
n_none.cpp: In function 'int main()':
n_none.cpp:2:17: error: 'gcd' is not a member of 'std'
    2 |     return std::gcd(12, 18) == 6 ? 0 : 1;
      |                 ^~~

The textbook version fails too - with no note to follow

The version most often written first - print the greatest common divisor of two values held in a vector, with std::cout - gets the same error, without <numeric>, and the same silence after it:

C++
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {12, 18};
    std::cout << std::gcd(v[0], v[1]) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 t_textbook.cpp -o t_textbook_prog
t_textbook.cpp: In function 'int main()':
t_textbook.cpp:5:23: error: 'gcd' is not a member of 'std'
    5 |     std::cout << std::gcd(v[0], v[1]) << "\n";
      |                       ^~~

What happened: on this library version, neither <vector> nor <iostream> pulls this name in transitively, so the call fails in a textbook file just as it does in a lean one - and there is no note pointing anywhere. In the sweep probed here, the only headers that rescue std::gcd besides <numeric> itself are <execution> and <random>, and those rescues are properties of this library version, not rules of the language. A program that uses std::gcd includes <numeric>, whether or not it happens to compile without it.

Neighboring headers: 103 fail the same way, and two rescue it

In a sweep where each of the 106 standard headers in this library's header set was compiled as the only header in a program that returns success if the greatest common divisor of 12 and 18 is 6, the outcome splits by compile result two ways. Every diagnostic component was classified separately - the error line, any suggestion tail on it, any note lines, and any help lines. These 103 headers all fail with the plain is not a member of 'std' error line, no suggestion tail on that line, no note lines at all, and no help lines:

  • <algorithm>
  • <any>
  • <array>
  • <atomic>
  • <barrier>
  • <bit>
  • <bitset>
  • <cassert>
  • <ccomplex>
  • <cctype>
  • <cerrno>
  • <cfenv>
  • <cfloat>
  • <charconv>
  • <chrono>
  • <cinttypes>
  • <ciso646>
  • <climits>
  • <clocale>
  • <cmath>
  • <codecvt>
  • <compare>
  • <complex>
  • <concepts>
  • <condition_variable>
  • <coroutine>
  • <csetjmp>
  • <csignal>
  • <cstdalign>
  • <cstdarg>
  • <cstdbool>
  • <cstddef>
  • <cstdint>
  • <cstdio>
  • <cstdlib>
  • <cstring>
  • <ctgmath>
  • <ctime>
  • <cuchar>
  • <cwchar>
  • <cwctype>
  • <deque>
  • <exception>
  • <expected>
  • <filesystem>
  • <format>
  • <forward_list>
  • <fstream>
  • <functional>
  • <future>
  • <initializer_list>
  • <iomanip>
  • <ios>
  • <iosfwd>
  • <iostream>
  • <istream>
  • <iterator>
  • <latch>
  • <limits>
  • <list>
  • <locale>
  • <map>
  • <memory>
  • <memory_resource>
  • <mutex>
  • <new>
  • <numbers>
  • <optional>
  • <ostream>
  • <queue>
  • <ranges>
  • <ratio>
  • <regex>
  • <scoped_allocator>
  • <semaphore>
  • <set>
  • <shared_mutex>
  • <source_location>
  • <span>
  • <spanstream>
  • <sstream>
  • <stack>
  • <stacktrace>
  • <stdexcept>
  • <stdfloat>
  • <stop_token>
  • <streambuf>
  • <string>
  • <string_view>
  • <syncstream>
  • <system_error>
  • <thread>
  • <tuple>
  • <type_traits>
  • <typeindex>
  • <typeinfo>
  • <unordered_map>
  • <unordered_set>
  • <utility>
  • <valarray>
  • <variant>
  • <vector>
  • <version>

A file with no include at all fails the same way, with the same absence of notes. No failing sole header prints a suggestion tail, a note line, or a help line in this sweep.

A sole <cmath> file shows the failing shape in full - and <cmath> is the header this call is most often expected in, since the name is a math function. It is not there. Neither is it in <algorithm>:

C++
#include <cmath>
int main() {
    return std::gcd(12, 18) == 6 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 v_cmath.cpp -o v_cmath_prog
v_cmath.cpp: In function 'int main()':
v_cmath.cpp:3:17: error: 'gcd' is not a member of 'std'
    3 |     return std::gcd(12, 18) == 6 ? 0 : 1;
      |                 ^~~
C++
#include <algorithm>
int main() {
    return std::gcd(12, 18) == 6 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 v_algorithm.cpp -o v_algorithm_prog
v_algorithm.cpp: In function 'int main()':
v_algorithm.cpp:3:17: error: 'gcd' is not a member of 'std'
    3 |     return std::gcd(12, 18) == 6 ? 0 : 1;
      |                 ^~~

And these headers rescue the program - it compiles and runs with no <numeric> anywhere in the file:

  • <execution>
  • <numeric>
  • <random>

Two contrasts with the neighboring sweeps are worth holding on to. First, there is no note class, no suggestion class, and no link-failure shape in this sweep: every failing sole header fails at compile time with the same bare error, so the header-naming notes that std::invoke carries - and the declared-but-not-defined link failure that std::swap produces behind five headers - have no counterpart for this name in the probed set. Second, the rescue set is exactly the one std::reduce - the other <numeric> name probed in this family - produced: the same two transitive rescues, <execution> and <random>. <numeric> - the home header - is on the rescue list by definition, not by transitivity, and the other two rescues are this library version's behavior, not a guarantee.

The fix

Add the header:

C++
#include <iostream>
#include <numeric>
int main() {
    std::cout << std::gcd(12, 18) << " "
              << std::gcd(48, 36) << " "
              << std::gcd(7, 13) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 h_fixed.cpp -o h_fixed_prog
$ ./h_fixed_prog
6 12 1

One include, <numeric>, declares the template: 12 and 18 share 6, 48 and 36 share 12, and the coprime pair 7 and 13 shares only 1, so the three calls are three different computations, not one answer repeated.

The fixed programs: signs are ignored, zero has a rule, and types may mix

The result is built from the absolute values of the arguments, so signs never change it - and a zero argument has an exact rule rather than an error: the greatest common divisor of 0 and a nonzero value is that value's absolute value, and std::gcd(0, 0) is 0 by definition:

C++
#include <iostream>
#include <numeric>
int main() {
    std::cout << std::gcd(-12, 18) << " "
              << std::gcd(12, -18) << " "
              << std::gcd(-12, -18) << " "
              << std::gcd(0, 5) << " "
              << std::gcd(5, 0) << " "
              << std::gcd(0, 0) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 k_signs.cpp -o k_signs_prog
$ ./k_signs_prog
6 6 6 5 5 0

Read in order: the three signed spellings of the 12-and-18 call all report 6; std::gcd(0, 5) and std::gcd(5, 0) each report 5; and std::gcd(0, 0) reports 0 - the one case where the divisor is defined to be zero rather than computed. Code that divides both arguments by their greatest common divisor still has to handle that case itself: the function returns 0 for it instead of failing.

The two arguments do not have to share a type. The template takes two integer types and returns their common type, so a long and an int, or an int and a long long, combine directly:

C++
#include <iostream>
#include <numeric>
int main() {
    std::cout << std::gcd(12L, 18) << " "
              << std::gcd(12, 18LL) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 k_mixed.cpp -o k_mixed_prog
$ ./k_mixed_prog
6 6

Both calls report 6. The common-type rule is also the boundary of the guarantee: if an argument's absolute value cannot be represented in the common type - the most negative value of a narrow signed type is the classic case - the behavior is undefined, so widening one argument is a correctness choice, not just a style one.

Versions: C++17 to call it, constexpr from the start, and no note either way

The call itself needs C++17, and unlike std::reduce - whose non-policy overloads became constexpr only in C++20 - std::gcd is constexpr from its introduction, so a static_assert over the call already compiles under C++17:

C++
#include <numeric>
int main() {
    static_assert(std::gcd(12, 18) == 6);
    static_assert(std::gcd(6, -10) == 2);
    return 0;
}
Command
$ g++ -std=c++17 c_constexpr17.cpp -o c_constexpr17_prog
$ ./c_constexpr17_prog

Under C++14 the name is not there at all, even with <numeric> included - and here this error's silence costs the most, because the output is identical to the missing-include case: the same plain error, and no version note to separate a too-old standard from a missing header:

Terminal
$ g++ -std=c++14 c_gcd14.cpp -o c_gcd14_prog
c_gcd14.cpp: In function 'int main()':
c_gcd14.cpp:3:17: error: 'gcd' is not a member of 'std'
    3 |     return std::gcd(12, 18) == 6 ? 0 : 1;
      |                 ^~~

Its sibling std::invoke gets a note naming the standard in exactly this situation; std::gcd does not. When the include is already in the file and the error persists, the standard flag is the next thing to check - the diagnostic will not tell you.

The neighboring names: lcm and midpoint share the one header

The names std::gcd is used alongside live in the same header. std::lcm - the least-common-multiple counterpart, also a C++17 constexpr template over two integer types - fails in the lean context here, only <limits> included, with its own plain error and the same absence of a note. It is shown here only as a neighbor, not re-taught:

C++
#include <limits>
int main() {
    return std::lcm(4, 6) == 12 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 b_lcm_lean.cpp -o b_lcm_lean_prog
b_lcm_lean.cpp: In function 'int main()':
b_lcm_lean.cpp:3:17: error: 'lcm' is not a member of 'std'
    3 |     return std::lcm(4, 6) == 12 ? 0 : 1;
      |                 ^~~

std::midpoint - the overflow-safe midpoint of two integers or pointers, the newer neighbor in the same header - fails the same way in the same lean context:

C++
#include <limits>
int main() {
    return std::midpoint(0, 10) == 5 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 b_midpoint_lean.cpp -o b_midpoint_lean_prog
b_midpoint_lean.cpp: In function 'int main()':
b_midpoint_lean.cpp:3:17: error: 'midpoint' is not a member of 'std'
    3 |     return std::midpoint(0, 10) == 5 ? 0 : 1;
      |                 ^~~~~~~~

The neighboring names, fixed

Each neighboring name works under the same one added header - there is no second header to reach for in this family. The fixed neighbor program reports 12 30 0 5: std::lcm(4, 6) is 12, std::lcm(6, 10) is 30, std::lcm(24, 0) is 0 - a zero argument makes the least common multiple zero, the mirror of the std::gcd zero rule - and std::midpoint(0, 10) is 5:

C++
#include <iostream>
#include <numeric>
int main() {
    std::cout << std::lcm(4, 6) << " "
              << std::lcm(6, 10) << " "
              << std::lcm(24, 0) << " "
              << std::midpoint(0, 10) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 b_neighbours_fixed.cpp -o b_neighbours_fixed_prog
$ ./b_neighbours_fixed_prog
12 30 0 5

One header, <numeric>, covers the whole conversation: gcd, lcm, and midpoint all take it, and a file that uses any of them and lacks it gets the same plain error with the name swapped. One version split does run through the family: std::gcd and std::lcm are C++17 names, while std::midpoint is newer - in the programs probed here it is absent under C++17 even with <numeric> included, and present under C++20.

A different wording - and no argument-dependent rescue for this name

Including <numeric> is not the only half of the name. This program includes the header, drops the std:: qualifier, and passes plain integers:

C++
#include <numeric>
int main() {
    return gcd(12, 18) == 6 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 g_unqualified.cpp -o g_unqualified_prog
g_unqualified.cpp: In function 'int main()':
g_unqualified.cpp:3:12: error: 'gcd' was not declared in this scope; did you mean 'std::gcd'?
    3 |     return gcd(12, 18) == 6 ? 0 : 1;
      |            ^~~
      |            std::gcd
In file included from g_unqualified.cpp:1:
/usr/include/c++/13/numeric:164:5: note: 'std::gcd' declared here
  164 |     gcd(_Mn __m, _Nn __n) noexcept
      |     ^~~

That wording - was not declared in this scope, with did you mean 'std::gcd'? on the error line and a note pointing at a declaration - is a different defect with a different fix: the header is present, the qualifier is not. Qualify the name as std::gcd; adding includes does not bring the name out of namespace std.

For std::reduce, the same unqualified call compiles when its arguments are std iterators, because argument-dependent lookup finds the name from the arguments. For std::gcd there is no such case in the programs probed here: integers are fundamental types and have no associated namespace, and wrapping an argument in a std type alias does not change that - std::common_type_t<int, int> is an alias for int, so the wrapped call fails with the same wording and the same note:

C++
#include <numeric>
#include <type_traits>
int main() {
    return gcd(std::common_type_t<int, int>(12), 18) == 6 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 g_unqualified_common.cpp -o g_unqualified_common_prog
g_unqualified_common.cpp: In function 'int main()':
g_unqualified_common.cpp:4:12: error: 'gcd' was not declared in this scope; did you mean 'std::gcd'?
    4 |     return gcd(std::common_type_t<int, int>(12), 18) == 6 ? 0 : 1;
      |            ^~~
      |            std::gcd
In file included from g_unqualified_common.cpp:1:
/usr/include/c++/13/numeric:164:5: note: 'std::gcd' declared here
  164 |     gcd(_Mn __m, _Nn __n) noexcept
      |     ^~~

So for this name the qualifier rule has no exception to learn: an unqualified gcd call is always the qualifier defect, never a working shortcut.

Integer arguments only: the error that comes from inside the header

One more failure shape belongs in this guide because it is so easily mistaken for the missing-name error's family: the header is included, the name is qualified, and the call still fails - because the arguments are not integers. With double arguments the failure comes from inside <numeric> itself, as a static assertion, followed by a second error in the type machinery:

C++
#include <numeric>
int main() {
    return std::gcd(12.0, 18.0) == 6.0 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 g_double.cpp -o g_double_prog
In file included from g_double.cpp:1:
/usr/include/c++/13/numeric: In instantiation of 'constexpr std::common_type_t<_Tp1, _Tp2> std::gcd(_Mn, _Nn) [with _Mn = double; _Nn = double; common_type_t<_Tp1, _Tp2> = double]':
g_double.cpp:3:20:   required from here
/usr/include/c++/13/numeric:166:21: error: static assertion failed: std::gcd arguments must be integers
  166 |       static_assert(is_integral_v<_Mn> && is_integral_v<_Nn>,
      |                     ^~~~~~~~~~~~~~~~~~
/usr/include/c++/13/numeric:166:21: note: 'std::is_integral_v<double>' evaluates to false
In file included from /usr/include/c++/13/bits/stl_iterator_base_types.h:67,
                 from /usr/include/c++/13/numeric:61:
/usr/include/c++/13/type_traits: In instantiation of 'struct std::make_unsigned<double>':
/usr/include/c++/13/type_traits:1983:11:   required by substitution of 'template<class _Tp> using std::make_unsigned_t = typename std::make_unsigned::type [with _Tp = double]'
/usr/include/c++/13/numeric:173:24:   required from 'constexpr std::common_type_t<_Tp1, _Tp2> std::gcd(_Mn, _Nn) [with _Mn = double; _Nn = double; common_type_t<_Tp1, _Tp2> = double]'
g_double.cpp:3:20:   required from here
/usr/include/c++/13/type_traits:1836:62: error: invalid use of incomplete type 'class std::__make_unsigned_selector<double, false, false>'
 1836 |     { typedef typename __make_unsigned_selector<_Tp>::__type type; };
      |                                                              ^~~~
/usr/include/c++/13/type_traits:1744:11: note: declaration of 'class std::__make_unsigned_selector<double, false, false>'
 1744 |     class __make_unsigned_selector;
      |           ^~~~~~~~~~~~~~~~~~~~~~~~

A bool argument is rejected the same way, by the matching assertion - static assertion failed: std::gcd arguments must not be bool - with a further error behind it. Neither shape is an include problem: the name was found, and the arguments were refused. Convert the values to an integer type - explicitly, so the conversion is visible - rather than adding headers.

The exact rule

  • std::gcd is declared by #include <numeric>, and by no other header by rule. In the sweep probed here, every one of the other 103 headers in the library's header set - among them <algorithm>, <cmath>, <iostream>, <vector>, <utility>, and <version> - does not declare it, and neither does a file with no include at all.
  • 'gcd' is not a member of 'std' means the <numeric> include is missing and nothing else in the file pulled the name in - or, under a standard before C++17, that the name does not exist yet in that standard. In every context probed here, GCC prints no suggestion tail on the error line, no note lines, and no help lines for this name - the missing-include case and the too-old-standard case print identically, and only the file's own include list and standard flag separate them.
  • In the sweep probed here, the split is two-way: a sole header either fails with that one uniform bare shape, or rescues the program. No probed sole header produces a note class, a suggestion class, or a declared-but-not-defined link-failure shape for this name - the contrast with std::invoke, whose failing headers all carry a note naming <functional>.
  • In the sweep probed here, only two headers besides <numeric> rescue std::gcd transitively - <execution> and <random>, the same two that rescue std::reduce - so a file whose only include is one of those compiles and runs the call without <numeric>. That is this library version's behavior, not a guarantee - in the probed set, neither header is required to pull std::gcd in.
  • The call works on absolute values and has an exact zero rule: the fixed programs here print 6 12 1 for std::gcd(12, 18), std::gcd(48, 36), and std::gcd(7, 13), and 6 6 6 5 5 0 for the signed spellings of the first call, for std::gcd(0, 5) and std::gcd(5, 0), and for std::gcd(0, 0) - the defined zero result that calling code dividing by the result still has to handle.
  • The two arguments may have different integer types and the result has their common type: the mixed program prints 6 6 for std::gcd(12L, 18) and std::gcd(12, 18LL). If an argument's absolute value is not representable in the common type, the behavior is undefined.
  • std::gcd is a C++17 function template and is constexpr since C++17: a static_assert over the call compiles under C++17, and under C++14 the name itself is absent with the same plain error and no note.
  • std::lcm and std::midpoint are declared by the same #include <numeric>: in the lean programs here, which include only <limits>, each gets its own is not a member of 'std' error, each with no note - and the fixed neighbor program prints 12 30 0 5 for std::lcm(4, 6), std::lcm(6, 10), std::lcm(24, 0), and std::midpoint(0, 10).
  • 'gcd' was not declared in this scope for an unqualified gcd use is a different defect: qualify the name as std::gcd - the include alone does not bring the name out of namespace std. For this name no argument-dependent-lookup case rescues the unqualified call in the programs probed here: integer arguments have no associated namespace, and an argument wrapped in std::common_type_t is still an integer underneath the alias, so both unqualified programs fail with the same wording.
  • The template is integer-only: with <numeric> included, a double argument fails inside the header with static assertion failed: std::gcd arguments must be integers, and a bool argument with the matching must not be bool assertion. Those are argument defects, not include defects.

The fixes, ranked

  • First, check the include list of the file that names std::gcd. If <numeric> is not there, add it - that is the fix in the common case, and it holds whether the file failed in a lean context, failed in a textbook file, or happened to compile before through a transitive rescue.
  • Second, do not wait for a note to confirm the header - for this error there is none. In the contexts probed here the diagnostic is one bare line; take the fix from the name's home header, <numeric>, not from the output.
  • Third, do not reach for <cmath> because the call is a math function, or for <algorithm> because it reads like an algorithm. In the sweep probed here, both fail for std::gcd with the same error - the integer numeric functions live in <numeric>, alongside std::lcm and the range algorithms of that header.
  • Fourth, do not be reassured by <iostream>, <vector>, or <string> being present - in the sweep here none of them rescues this name at all - and do not remove <numeric> because a file compiles without it: in the probed set only <execution> and <random> rescue it, and those rescues are not guaranteed.
  • Fifth, check the standard before changing the code when the include is already right. Under C++14 this name does not exist; under C++17 it exists and is already constexpr, so no C++20 upgrade is needed for a static_assert over the call. The diagnostic will not separate these cases, so read the build's standard flag directly.
  • Sixth, if the error says was not declared in this scope instead, fix the name's qualifier to std::gcd as well - and do not look for an argument-dependent-lookup case that makes the unqualified call work, because for integer arguments there is none.
  • Seventh, if the failure is a static assertion from inside <numeric> - must be integers, or must not be bool - the include and the qualifier are both already right: convert the arguments to an integer type, explicitly.
  • Eighth, if the failing name is a neighboring one, the fix is the same header: lcm and midpoint take the same added <numeric> - one include for the whole family.

Which fix for which cause

  • #include <numeric> missing, std::gcd used in a file whose only include is one of the 103 headers listed as failing in the sweep section above, or that includes nothing: the message is 'gcd' is not a member of 'std', with no suggestion tail, no note lines, and no help lines - add #include <numeric>.
  • std::gcd used in a textbook file including <iostream> and <vector>: the message is the same bare error - add #include <numeric>.
  • std::gcd used with only <numeric>, <execution>, or <random> included: no error on this library version - add #include <numeric> anyway when it is not the include already present, because the <execution> and <random> rescues are not guaranteed.
  • std::gcd used with <numeric> included under C++14: the message is 'gcd' is not a member of 'std' with no note - compile as C++17 or later. A static_assert over the call needs only C++17, where the template is already constexpr.
  • std::lcm or std::midpoint used without <numeric> in the lean context: the message names that name, with no note - add #include <numeric>. For std::midpoint the standard matters as well: it is absent under C++17 even with the header included, in the programs probed here.
  • gcd used without the std:: qualifier, <numeric> included, over integer arguments - plain or wrapped in std::common_type_t: the message is 'gcd' was not declared in this scope; did you mean 'std::gcd'? - qualify the name as std::gcd.
  • std::gcd called with double or bool arguments, <numeric> included: the message is a static assertion from inside the header - std::gcd arguments must be integers, or std::gcd arguments must not be bool - convert the arguments to an integer type; no include change fixes this shape.

Checklist

  • Check the include list of the file that names the call, not just the project. The include must be in that file, or in a header that file includes directly by design.
  • Do not read the absence of a note as a different error. For this name the missing-include diagnostic is one bare line in every probed context; the note that names the home header for std::invoke has no counterpart here.
  • Do not import a neighboring family's split into this error: in this family every name - gcd, lcm, midpoint - takes the same <numeric>, so there is no per-name header to look up.
  • Do not assume the textbook includes rescue this name, and do not delete a working <numeric> line because a file compiles without it. In the sweep here <iostream> and <vector> do not rescue std::gcd at all, and the two headers that do rescue it do so only transitively.
  • Match the standard to the use: the call itself needs C++17 and <numeric>, and a constant-expression call needs nothing more - this template is constexpr from C++17, unlike std::reduce, whose constexpr arrived in C++20.
  • Handle the zero result before dividing by it: std::gcd(0, 0) is defined as 0, so code that divides both arguments by their greatest common divisor needs its own guard for the both-zero case.
  • Check the argument types before adding headers: a failure whose first error is a static assertion inside <numeric> is an argument defect - non-integer and bool arguments are refused there, with the header already included.
  • After the fix, confirm the program runs, not just that it compiles: the fixed programs here print 6 12 1 for the three plain calls, 6 6 6 5 5 0 for the signed and zero cases, and 12 30 0 5 for the neighbor calls.
  • 'std::reduce' Is Not a Member of 'std' Fix - the same missing-include shape for the range reduction in <numeric>: its sweep is identical in shape to this one - the same 103 uniform bare failures and the same two transitive rescues, <execution> and <random> - and the two guides differ mainly in the version rule, since std::reduce is constexpr only since C++20 where std::gcd is constexpr since C++17.
  • 'std::invoke' Is Not a Member of 'std' Fix - the same missing-include shape for the uniform call wrapper in <functional>: its sweep is just as uniform, but every failing header there carries a note naming the home header, where this guide's failing headers carry no note at all.

Sources

  • cppreference, std::gcd — for std::gcd being a function template defined in <numeric> since C++17, constexpr since C++17, that computes the greatest common divisor of two integers, returns zero if both arguments are zero and otherwise the greatest common divisor of their absolute values, whose result type is the common type of the two argument types, that is ill-formed when an argument type is not an integer type or is bool, whose behavior is undefined when an argument's absolute value is not representable in the common type, and whose feature-test macro is __cpp_lib_gcd_lcm (201606L, C++17).
  • cppreference, Standard library header <numeric> — for <numeric> being the header that declares std::gcd alongside std::lcm, std::midpoint, std::accumulate, std::reduce, std::inner_product, std::transform_reduce, std::partial_sum, the scan family, and std::adjacent_difference.
  • cppreference, std::lcm — for std::lcm being a function template defined in <numeric> since C++17, constexpr since C++17, that computes the least common multiple of two integers, returns zero if either argument is zero and otherwise the least common multiple of their absolute values, and shares the __cpp_lib_gcd_lcm feature-test macro with std::gcd.

Keep Exploring