[Bug c++/31511] New: /usr/include/c++/bits/cmath.tcc: no match for ternary 'operator?:' in '((__n % 2u) != 0u) ? __x : 1'
It is known problem with GNU ISO C++ Library math implementation by Gabriel Dos Reis. g++ compiler says something like this: /usr/include/c++/bits/cmath.tcc:41: error: no match for ternary 'operator?:' in '((__n % 2u) != 0u) ? __x : 1' It could be fixed by replacing the certain line at the cmath.tcc file _Tp __y = __n % 2 ? __x : 1; with more correct _Tp __y = __n % 2 ? __x : _Tp(1); (see cmath.tcc for details) To reproduce error, try to pass to std::pow() std::complex object where T isn't primitive type but some class with arithmetic operators overloaded. I found it in g++ 3.3.5, g++ 4.0.0, etc. -- Summary: /usr/include/c++/bits/cmath.tcc: no match for ternary 'operator?:' in '((__n % 2u) != 0u) ? __x : 1' Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: bav dot 272304 at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31511
[Bug c++/31511] /usr/include/c++/bits/cmath.tcc: no match for ternary 'operator?:' in '((__n % 2u) != 0u) ? __x : 1'
--- Comment #2 from bav dot 272304 at gmail dot com 2007-04-08 21:16 --- Code example: #include template class Wrapper { T x_; public: Wrapper () throw () : x_(0) {} Wrapper (const T& x) throw () : x_(x) {} Wrapper operator* (const Wrapper& x) const throw () { return Wrapper (x_*x.x_); } Wrapper operator/ (const Wrapper& x) const throw () { return Wrapper (x_/x.x_); } Wrapper operator+ (const Wrapper& x) const throw () { return Wrapper (x_+x.x_); } Wrapper operator- (const Wrapper& x) const throw () { return Wrapper (x_-x.x_); } Wrapper operator- () const throw () { return Wrapper (-x_); } ~Wrapper () throw () {} }; int main () { std::complex > x (Wrapper(2.0)); std::pow (x, 23); } OUTPUT: debian:/# g++ bug.cpp --pedantic --std=c++98 -Wall /usr/include/c++/3.3/bits/cmath.tcc: In function `_Tp std::__cmath_power(_Tp, unsigned int) [with _Tp = std::complex >]': /usr/include/c++/3.3/cmath:477: instantiated from `_Tp std::__pow_helper(_Tp, int) [with _Tp = std::complex >]' /usr/include/c++/3.3/complex:564: instantiated from `std::complex<_Tp> std::pow(const std::complex<_Tp>&, int) [with _Tp = Wrapper]' bug.cpp:29: instantiated from here /usr/include/c++/3.3/bits/cmath.tcc:42: error: no match for ternary 'operator?:' in '((__n % 2) != 0) ? __x : 1' -- bav dot 272304 at gmail dot com changed: What|Removed |Added ------------------------ CC| |bav dot 272304 at gmail dot ||com Component|libstdc++ |c++ http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31511
[Bug c++/31511] /usr/include/c++/bits/cmath.tcc: no match for ternary 'operator?:' in '((__n % 2u) != 0u) ? __x : 1'
--- Comment #3 from bav dot 272304 at gmail dot com 2007-04-08 21:17 --- (In reply to comment #1) > Gaby, not a big deal (complex is unspecified for T != floating, ...), but > what do you think, shall we do the 1 -> _Tp(1) change? > No, everything works if we fix this bug. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31511
[Bug c++/31511] /usr/include/c++/bits/cmath.tcc: no match for ternary 'operator?:' in '((__n % 2u) != 0u) ? __x : 1'
--- Comment #5 from bav dot 272304 at gmail dot com 2007-04-08 21:21 --- (In reply to comment #1) > but what do you think, shall we do the 1 -> _Tp(1) change? Change, please. -- bav dot 272304 at gmail dot com changed: What|Removed |Added Component|libstdc++ |c++ http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31511