C++

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

std::move is declared by one header by specification, <utility> - but on this library most other headers pull it in along the way, so the error only shows up in a file whose includes happen not to. This guide pins down when the error appears, which probed headers do and do not cause it, and the one include that fixes it by specification.

Written November 30, 2026 · Tested with GCC 13.3.0 · 13 min read

By the end of this guide
  • The error: no declaring header in the file
  • Neighboring headers: most of them rescue it
  • The fix
  • The neighboring names: the whole header family fails too

Written November 30, 2026

Tested with GCC 13.3.0

What this guide is

std::move is a function template defined in the header <utility>. It is used to indicate that an object may be "moved from", allowing the efficient transfer of resources from that object to another object: in particular, std::move produces an xvalue expression that identifies its argument, and it is exactly equivalent to a static_cast to an rvalue reference type. The functions that accept rvalue reference parameters - move constructors, move assignment operators, and regular member functions such as std::vector::push_back - are selected by overload resolution when called with rvalue arguments, either prvalues such as a temporary object or xvalues such as the one produced by std::move.

Because the template is declared by one specific header, 'move' is not a member of 'std' has one common cause:

  • The file includes no header that declares std::move. For this error GCC does name the header: its note says 'std::move' is defined in header '<utility>'; did you forget to '#include <utility>'?, and following that note is the whole fix.

Unlike some neighboring names, this error is shy: most headers that sit near move code rescue the program transitively on this library, so the error only appears in a file whose include list happens to avoid all of them. Each case is separated below.

The error: no declaring header in the file

This program converts an int to an rvalue with std::move, but includes only <type_traits> - a header that declares type traits, not std::move:

C++
#include <type_traits>
int main() {
    int source = 42;
    int target = std::move(source);
    return target;
}
Terminal
$ g++ -std=c++20 a_noinclude.cpp -o a_noinclude_prog
a_noinclude.cpp: In function 'int main()':
a_noinclude.cpp:4:23: error: 'move' is not a member of 'std'
    4 |     int target = std::move(source);
      |                       ^~~~
a_noinclude.cpp:2:1: note: 'std::move' is defined in header '<utility>'; did you forget to '#include <utility>'?
    1 | #include <type_traits>
  +++ |+#include <utility>
    2 | int main() {

The error is the defect, and the note under it names the fix directly. There are no knock-on errors in this short program: the failed conversion is the only use of the missing name.

Neighboring headers: most of them rescue it

Swapping <type_traits> for another nearby header changes the outcome - in the opposite direction from most missing-include errors. In a sweep where each header below was compiled as the only header in a program that converts an int with std::move and returns whether the result is 42, each of these causes the program to compile and run:

  • <utility> - the header that declares std::move by specification; this is the control case, not a rescue
  • <string>
  • <vector>
  • <memory>
  • <algorithm>
  • <thread>
  • <future>
  • <mutex>
  • <iostream>
  • <functional>

Only <type_traits> fails, with the same first error, 'move' is not a member of 'std', and the same note naming <utility>.

The same holds when the program uses the move the way real code does. This program includes only <iostream>:

C++
#include <iostream>
int main() {
    int source = 42;
    int target = std::move(source);
    std::cout << target << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 t_iostream.cpp -o t_prog
$ ./t_prog
42

It compiles and prints 42 - <iostream> pulls std::move in transitively on this library, even though no header except <utility> is required to declare it. That is a property of this library version, not a rule of the language: another library could leave the name out, and a program that relied on the rescue would break there. A program that uses std::move includes <utility>, whether or not it happens to compile without it.

The fix

Add the header:

C++
#include <iostream>
#include <string>
#include <utility>
int main() {
    std::string source = "hello";
    std::string target = std::move(source);
    std::cout << target << "\n";
    std::cout << source.size() << "\n";
    std::cout << "[" << source << "]\n";
    return 0;
}
Terminal
$ g++ -std=c++20 h_fixed.cpp -o h_prog
$ ./h_prog
hello
0
[]

One include, <utility>, declares the function template. The moved-to string prints hello. The moved-from string prints with size 0 and empty contents in this run - but that is this library's choice, not a guarantee: unless otherwise specified, standard library objects that have been moved from are placed in a valid but unspecified state, so code after a move may rely on the object's invariants holding, not on any particular value.

The same include fixes a moved vector - the target takes the three elements, and the source is left with size 0 in this run:

C++
#include <iostream>
#include <utility>
#include <vector>
int main() {
    std::vector<int> source = {1, 2, 3};
    std::vector<int> target = std::move(source);
    std::cout << target.size() << "\n";
    std::cout << target[0] << target[1] << target[2] << "\n";
    std::cout << source.size() << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 i_vector_fixed.cpp -o i_prog
$ ./i_prog
3
123
0

And a moved std::unique_ptr - the target dereferences to 42, and the source compares equal to nullptr afterward, which prints as 1:

C++
#include <iostream>
#include <memory>
#include <utility>
int main() {
    std::unique_ptr<int> source = std::make_unique<int>(42);
    std::unique_ptr<int> target = std::move(source);
    std::cout << *target << "\n";
    std::cout << (source == nullptr) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 j_unique_fixed.cpp -o j_prog
$ ./j_prog
42
1

The neighboring names: the whole header family fails too

The other names declared by <utility> fail with the same shape of error when no header declares them. std::forward - the function template that forwards a function argument, using the type template argument to preserve its value category - gets its own error and its own note in a file that includes only <type_traits>:

C++
#include <type_traits>
template <typename T> int relay(T&& value) { return std::forward<T>(value); }
int main() { return relay(42); }
Terminal
$ g++ -std=c++20 b_forward.cpp -o b_forward_prog
b_forward.cpp: In function 'int relay(T&&)':
b_forward.cpp:2:58: error: 'forward' is not a member of 'std'
    2 | template <typename T> int relay(T&& value) { return std::forward<T>(value); }
      |                                                          ^~~~~~~
b_forward.cpp:2:1: note: 'std::forward' is defined in header '<utility>'; did you forget to '#include <utility>'?
    1 | #include <type_traits>
  +++ |+#include <utility>
    2 | template <typename T> int relay(T&& value) { return std::forward<T>(value); }
b_forward.cpp:2:67: error: expected primary-expression before '>' token
    2 | template <typename T> int relay(T&& value) { return std::forward<T>(value); }
      |                                                                   ^

std::exchange - the function template that replaces its argument with a new value and returns the argument's previous value - fails the same way in a file that includes only <iostream>. Note the contrast with std::move itself: <iostream> rescues std::move transitively in the sweep above, but it does not declare std::exchange, so this program still fails, again with its own note naming <utility>:

C++
#include <iostream>
int main() {
    int value = 42;
    int old = std::exchange(value, 7);
    std::cout << old << value << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 d_exchange.cpp -o d_prog
d_exchange.cpp: In function 'int main()':
d_exchange.cpp:4:20: error: 'exchange' is not a member of 'std'
    4 |     int old = std::exchange(value, 7);
      |                    ^~~~~~~~
d_exchange.cpp:2:1: note: 'std::exchange' is defined in header '<utility>'; did you forget to '#include <utility>'?
    1 | #include <iostream>
  +++ |+#include <utility>
    2 | int main() {

std::swap - the function template that swaps the values of two objects - fails the same way in a file with no includes at all, except that GCC prints no header note under this error:

C++
int main() {
    int a = 1;
    int b = 2;
    std::swap(a, b);
    return a;
}
Terminal
$ g++ -std=c++20 c_swap.cpp -o c_prog
c_swap.cpp: In function 'int main()':
c_swap.cpp:4:10: error: 'swap' is not a member of 'std'
    4 |     std::swap(a, b);
      |          ^~~~

And std::declval - the function template that obtains a reference to an object of the template type argument for use in an unevaluated context - fails the same way, with its own note naming <utility>, in a file with no includes at all:

C++
int main() {
    using T = decltype(std::declval<int>());
    return 0;
}
Terminal
$ g++ -std=c++20 e_declval.cpp -o e_declval_prog
e_declval.cpp: In function 'int main()':
e_declval.cpp:2:29: error: 'declval' is not a member of 'std'
    2 |     using T = decltype(std::declval<int>());
      |                             ^~~~~~~
e_declval.cpp:1:1: note: 'std::declval' is defined in header '<utility>'; did you forget to '#include <utility>'?
  +++ |+#include <utility>
    1 | int main() {
e_declval.cpp:2:29: error: 'declval' is not a member of 'std'
    2 |     using T = decltype(std::declval<int>());
      |                             ^~~~~~~
e_declval.cpp:2:29: note: 'std::declval' is defined in header '<utility>'; did you forget to '#include <utility>'?
e_declval.cpp:2:37: error: expected primary-expression before 'int'
    2 |     using T = decltype(std::declval<int>());
      |                                     ^~~

std::declval has one quirk the others do not: in the sweep design used for std::move, a file that includes only <type_traits> compiles a std::declval use cleanly - <type_traits> rescues std::declval transitively even though it does not rescue std::move. One added include, <utility>, declares every one of these names by specification: the move, the forward, the exchange, the swap, and the declval.

The neighboring names, fixed

With <utility> added, the forward, the swap, the exchange, and the declval all work in short programs. The forwarding relay returns the value it was given, preserving its value category on the way through:

C++
#include <iostream>
#include <utility>
template <typename T> int relay(T&& value) { return std::forward<T>(value); }
int main() { std::cout << relay(42) << "\n"; return 0; }
Terminal
$ g++ -std=c++20 i_forward_fixed.cpp -o i_forward_fixed_prog
$ ./i_forward_fixed_prog
42

The swap exchanges the two values, so the pair that started as 1 and 2 prints as 21:

C++
#include <iostream>
#include <utility>
int main() {
    int a = 1;
    int b = 2;
    std::swap(a, b);
    std::cout << a << b << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 j_swap_fixed.cpp -o j_swap_fixed_prog
$ ./j_swap_fixed_prog
21

The exchange returns the previous value and leaves the new one in place, so the program prints the old 42 and the new 7:

C++
#include <iostream>
#include <utility>
int main() {
    int value = 42;
    int old = std::exchange(value, 7);
    std::cout << old << " " << value << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 k_exchange_fixed.cpp -o k_exchange_fixed_prog
$ ./k_exchange_fixed_prog
42 7

And std::declval<int>() has type int&& in an unevaluated context, so the comparison against int&& prints 1:

C++
#include <iostream>
#include <type_traits>
#include <utility>
int main() {
    std::cout << std::is_same_v<decltype(std::declval<int>()), int&&> << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 l_declval_fixed.cpp -o l_declval_fixed_prog
$ ./l_declval_fixed_prog
1

A different wording: the name without its qualifier

Including <utility> is not the only half of the name. This program includes the header but drops the std:: qualifier, and uses an int - a type with no namespace of its own to find the name through:

C++
#include <iostream>
#include <utility>
int main() {
    int source = 42;
    int target = move(source);
    std::cout << target << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 g_unqualified.cpp -o g_prog
g_unqualified.cpp: In function 'int main()':
g_unqualified.cpp:5:18: error: 'move' was not declared in this scope; did you mean 'std::move'?
    5 |     int target = move(source);
      |                  ^~~~
      |                  std::move
In file included from /usr/include/c++/13/string:51,
                 from /usr/include/c++/13/bits/locale_classes.h:40,
                 from /usr/include/c++/13/bits/ios_base.h:41,
                 from /usr/include/c++/13/ios:44,
                 from /usr/include/c++/13/ostream:40,
                 from /usr/include/c++/13/iostream:41,
                 from g_unqualified.cpp:1:
/usr/include/c++/13/bits/stl_algobase.h:657:5: note: 'std::move' declared here
  657 |     move(_II __first, _II __last, _OI __result)
      |     ^~~~

That wording - was not declared in this scope - is a different defect with a different fix: the header is present, the qualifier is not. Qualify the name as std::move; adding includes does not bring the name out of namespace std.

The exact rule

  • std::move is declared by #include <utility>, and nowhere else by rule. In the sweep probed here, <string>, <vector>, <memory>, <algorithm>, <thread>, <future>, <mutex>, <iostream>, and <functional> also cause the program to compile on GCC 13.3.0, by transitive inclusion - and <type_traits> does not.
  • 'move' is not a member of 'std' means no header in the file declares std::move, and GCC's note names the header directly: 'std::move' is defined in header '<utility>'. Follow the note.
  • In the sweep probed here, the transitive rescues are complete, not partial: every rescuing header makes the program compile and run, and there is no header in the sweep that makes only the title error disappear while leaving the name unusable.
  • std::forward, std::exchange, std::swap, and std::declval are declared by the same #include <utility>: in the programs shown here, each gets its own is not a member of 'std' error when no header declares it - with a header note for move, forward, exchange, and declval, and without one for swap. Their rescues differ, though: <iostream> does not declare std::exchange, and <type_traits> rescues std::declval while not rescuing std::move.
  • 'move' was not declared in this scope for an unqualified move use is a different defect: qualify the name as std::move - the include alone does not bring the name out of namespace std.
  • A moved-from standard library object is in a valid but unspecified state unless otherwise specified: the moved-from string and vector in the fixed programs here print empty, but that is this library's choice, not a value portable code may assume.

The fixes, ranked

  • First, check the include list of the file that names std::move. If <utility> is not there, add it - that is the fix in the common case, and it is the fix GCC's own note names.
  • Second, do not be reassured by a file that compiles without <utility>. In the sweep here, nine neighboring headers rescue the name transitively; that rescue is a property of this library version, and the file breaks on a library that does not perform it.
  • Third, do not chase the follow-on errors. Fix the include and recompile; the expected-expression errors that follow a failed template name are consequences, not causes.
  • Fourth, if the error says was not declared in this scope instead, fix the name's qualifier to std::move as well.
  • Fifth, if the failing name is a neighboring one - forward, exchange, swap, or declval - the same added include fixes it by specification: every one of those names shares the header. One of them, swap, gets no note in the program here; the fix is the same header. Do not assume their transitive rescues match std::move's - in the programs here, they do not.

Which fix for which cause

  • #include <utility> missing and no rescuing header in the file, std::move used with <type_traits> present: the message is 'move' is not a member of 'std' - add #include <utility>.
  • Only a header from the rescuing side of the sweep included - <string>, <vector>, <memory>, <algorithm>, <thread>, <future>, <mutex>, <iostream>, or <functional>: the program compiles on this library without <utility> - add #include <utility> anyway, so the file does not depend on a transitive inclusion no header is required to provide.
  • std::forward or std::exchange used without a declaring header: the message names that name, with a note naming <utility> - add #include <utility>.
  • std::swap used with no includes at all: the message names swap, with no header note from GCC - add #include <utility>.
  • std::declval used with no includes at all: the message names declval, with a note naming <utility> - add #include <utility>. With only <type_traits> included, the same use compiles on this library.
  • move used without the std:: qualifier, <utility> included: the message is 'move' was not declared in this scope - qualify the name as std::move.

Checklist

  • Check the include list of the file that names the move, not just the project. The include must be in that file, or in a header that file includes directly by design - a transitive rescue through <iostream> or <vector> is not by design.
  • Read the note under the error. For this error GCC names the header - 'std::move' is defined in header '<utility>' - so take the fix from the note instead of guessing. One neighboring name, swap, gets no note in the program here; the fix is the same header.
  • Do not rely on a neighboring header pulling std::move in. In the sweep here, nine of the eleven probed headers do - and no header except <utility> is required to.
  • One header per name the file uses: std::string comes from <string> and std::vector from <vector>, even in a program whose subject is the move - and neither of those headers is required to declare std::move in return, whatever this library happens to do.
  • After the fix, confirm the program runs, not just that it compiles: the fixed programs here print hello for the moved-to string with the moved-from string at size 0, 3 and 123 for the moved vector with its source at size 0, and 42 and 1 for the moved unique pointer and its emptied source.

Sources

  • cppreference, std::move - for std::move being a function template defined in <utility> (since C++11) that indicates an object may be moved from, produces an xvalue expression identifying its argument, and is exactly equivalent to a static_cast to an rvalue reference type, for the rvalue-reference overloads being selected when called with rvalue arguments, and for moved-from standard library objects being in a valid but unspecified state unless otherwise specified.
  • cppreference, Standard library header <utility> - for <utility> declaring std::swap, std::exchange (since C++14), std::forward (since C++11), std::move (since C++11), and std::declval (since C++11) as function templates.
  • cppreference, std::forward - for std::forward forwarding a function argument and using the type template argument to preserve its value category.
  • cppreference, std::exchange - for std::exchange replacing its argument with a new value and returning its previous value.
  • cppreference, std::declval - for std::declval obtaining a reference to an object of the template type argument for use in an unevaluated context.

Keep Exploring