Pythy
Pythy copied to clipboard
PYTHY fails in gcc (4.7.1)
I tried compiling a simple example:
#include "pythy.h"
#include <iostream>
PYTHY(min, x, y)
( return x < y ? x : y; )
int main(int argc, char* argv[]) {
std::cerr << min(5,0) << "\n";
}
but the compiler seems to error out:
test.cpp: In instantiation of 'struct pythy_min4<int, int>':
test.cpp:4:1: required by substitution of 'template<class T0, class T1> decltype ((* pythy_min4<T0, T1>::p)(forward<T0>(x0), forward<T1>(x1))) min(T0&&, T1&&) [with T0 = int; T1 = int]'
test.cpp:9:25: required from here
test.cpp:4:1: error: declaration of 'constexpr auto* const pythy_min4<int, int>::p' has no initializer
test.cpp: In function 'int main(int, char**)':
test.cpp:9:25: error: no matching function for call to 'min(int, int)'
test.cpp:9:25: note: candidate is:
test.cpp:4:1: note: template<class T0, class T1> decltype ((* pythy_min4<T0, T1>::p)(forward<T0>(x0), forward<T1>(x1))) min(T0&&, T1&&)
test.cpp:4:1: note: substitution of deduced template arguments resulted in errors seen above
Any idea what causing things to go awry?
This is a bug in gcc. They don't support defining auto constexpr variables within template contexts. I don't if they have fixed it in gcc 4.8. However, it will work in clang 3.1 or higher.