https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89931
Bug ID: 89931 Summary: Incorrect compiler error with temporary object used as function arguments Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: dchneric at gmail dot com Target Milestone: --- Created attachment 46076 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46076&action=edit zip package including source and temp files The following code --- #include <iostream> void foo(const char**) { std::cout << "do something"; } int main() { using argT = const char*[]; foo(argT{"a", "b"}); return 0; } --- errors out due to following error: --- main.cpp:7:9: error: taking address of temporary array foo(argT{"a", "b"}); --- However, at line 7, adding std::move before invoking foo(), i.e.: --- foo(std::move(argT{"a", "b"})); --- suppresses the error. Other compilers like MSVC, ICC, Clang does not have this issue. ------------------- VERSION & SYSTEM: gcc version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1) Target: x86_64-linux-gnu Thread model: posix INSTALL CMD: apt-get install COMPILATION FAILURE DETAIL: % gcc -Wall -Wextra main.cpp -o a.out main.cpp: In function int main() : main.cpp:7:9: error: taking address of temporary array foo(argT{"a", "b"}); ^~~~~~~~~~~~~~ MORE INFO: https://stackoverflow.com/questions/55463861/why-does-passing-a-temporary-object-as-an-argument-need-stdmove