Hi, the following program does not compile with g++4.9.2:
#include <iostream> template<typename T> auto tt(T x) -> decltype(~x) // <-- here { return ~x; } int main() { std::cout << tt(10) << std::endl; return EXIT_SUCCESS; } ptomulik@tea:$ g++ -std=c++11 -g -O0 -Wall -Wextra -Werror -pedantic -o test-gcc test.cpp test.cpp: In function ‘int main()’: test.cpp:10:21: error: no matching function for call to ‘tt(int)’ std::cout << tt(10) << std::endl; ^ test.cpp:10:21: note: candidate is: test.cpp:5:6: note: template<class T> decltype (~ x) tt(T) auto tt(T x) -> decltype(~x) ^ test.cpp:5:6: note: template argument deduction/substitution failed: test.cpp: In substitution of ‘template<class T> decltype (~ x) tt(T) [with T = int]’: test.cpp:10:21: required from here test.cpp:5:6: error: ‘x’ was not declared in this scope This is specific to operator "~". Note, that, for example, any of the following functions compile without a problem: template<typename T> auto tt(T x) -> decltype(-x) { return -x; } template<typename T> auto tt(T x) -> decltype(!x) { return !x; } template<typename T> auto tt(T x) -> decltype(+x) { return +x; } template<typename T> auto tt(T x) -> decltype(~T()) { return ~x; } Is this a bug? The original program compiles with clang. Best Regards! -- Pawel Tomulik