https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65091
Bug ID: 65091 Summary: decltype(~arg) fails for template functions Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: ptomulik at meil dot pw.edu.pl Created attachment 34790 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34790&action=edit ii file generated by -save-temps The following program does not compile with g++ (although it compiles with clang++): template<typename T> auto foo(T x) -> decltype(~x) { return ~x; } int bar() { return foo(10); } ptomulik@tea:$ g++ -std=c++11 -g -O0 -Wall -Wextra -Werror -pedantic -c -o test.o test.cpp test.cpp: In function ‘int bar()’: test.cpp:6:16: error: no matching function for call to ‘foo(int)’ { return foo(10); } ^ test.cpp:6:16: note: candidate is: test.cpp:2:6: note: template<class T> decltype (~ x) foo(T) auto foo(T x) -> decltype(~x) ^ test.cpp:2:6: note: template argument deduction/substitution failed: test.cpp: In substitution of ‘template<class T> decltype (~ x) foo(T) [with T = int]’: test.cpp:6:16: required from here test.cpp:2:6: error: ‘x’ was not declared in this scope test.cpp:6:19: error: control reaches end of non-void function [-Werror=return-type] { return foo(10); } ^ cc1plus: all warnings being treated as errors This is specific to the unary operator "~" and expression involving argument name (not its type). All the following variants compile well for instance: template<typename T> auto foo(T x) -> decltype(!x) { return !x; } template<typename T> auto foo(T x) -> decltype(-x) { return -x; } template<typename T> auto foo(T x) -> decltype(+x) { return +x; } template<typename T> auto foo(T x) -> decltype(~T()) { return ~x; } My gcc is: ptomulik@tea:$ g++ --version g++-4.9.real (Debian 4.9.2-10) 4.9.2 Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. My OS is Debian 8.0.