Pythy icon indicating copy to clipboard operation
Pythy copied to clipboard

PYTHY fails in gcc (4.7.1)

Open rob-p opened this issue 13 years ago • 1 comments

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?

rob-p avatar Sep 27 '12 14:09 rob-p

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.

pfultz2 avatar Sep 30 '12 05:09 pfultz2