This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Operator "~", decltype() and templates.
- From: PaweÅ Tomulik <ptomulik at meil dot pw dot edu dot pl>
- To: gcc at gcc dot gnu dot org
- Date: Tue, 17 Feb 2015 16:10:39 +0100
- Subject: Operator "~", decltype() and templates.
- Authentication-results: sourceware.org; auth=none
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