1

After upgrading from gcc 6.1 to to 7.1, some of my code no longer compiles:

include\jw\vector2.h: In member function 'constexpr jw::vector2<T>& jw::vector2<T>::operator=(const jw::vector2<U>&)':
include\jw\vector2.h(32,119): error :  expected primary-expression before '>' token
        template <typename U> constexpr vector2& operator=(const vector2<U>& rhs) noexcept { return *this = rhs.cast<T>(); };
                                                                                                                      ^
include\jw\vector2.h(32,121): error :  expected primary-expression before ')' token
        template <typename U> constexpr vector2& operator=(const vector2<U>& rhs) noexcept { return *this = rhs.cast<T>(); };
                                                                                                                        ^

I'm getting about ~20 of these errors in various classes using template functions. In this case vector2 is a simple template class, defined as:

template <typename T> struct vector2
{ /* ... */ }

and cast is a member function of vector2, defined as:

template <typename U> constexpr vector2<U> cast() const noexcept 
{ 
    return vector2<U>{ std::is_integral<U>::value ? this->rounded() : *this }; 
}

Frankly I don't see the problem here and the error message doesn't point at any obvious issues. Any ideas why this suddenly fails?

user5434231
  • 579
  • 3
  • 16
  • 3
    `return *this = rhs.template cast();` should solve your issue. – Jarod42 May 04 '17 at 18:23
  • 1
    I only know that gcc 7.1 no longer accepts illegal constructs using templates: your functions are and were ill-formed, but gcc 6 falsely accepted them. I don't know why though – Rakete1111 May 04 '17 at 18:24
  • @Jarod42, thank you! Never knew that was ill-formed. Guess I couldn't have known either since gcc previously never complained about it. – user5434231 May 04 '17 at 19:29

0 Answers0