Class template specialization, operator overloading, Compiler Explorer generating extra qualification error [duplicate]

A simple templated 4×4 matrix class using vector intrinsics, thus the need for template specialization to support both integer and floating-point types.

I have the following compiler and flags set:

  • x86-64 gcc 14.1
    • flags: g++ -std=c++17 -O3 -msse2

Here’s the generated error

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><source>:66:5: error: extra qualification 'Mat4<T>::' on member
'operator+' [-fpermissive]
66 | Mat4<T>::operator+(const Mat4& other) const {
| ^~~~~~~
</code>
<code><source>:66:5: error: extra qualification 'Mat4<T>::' on member 'operator+' [-fpermissive] 66 | Mat4<T>::operator+(const Mat4& other) const { | ^~~~~~~ </code>
<source>:66:5: error: extra qualification 'Mat4<T>::' on member 

    'operator+' [-fpermissive]
       66 |     Mat4<T>::operator+(const Mat4& other) const {
          |     ^~~~~~~

I narrowed it down to one specific example using the operator+() overload, one case for integer type and one specialization for float.

Source: sample.cpp

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>#include <algorithm> // std::clamp
#include <cstdint> // std::uint8_t
#include <immintrin.h> // SSE/SSE2 intrinsics
#include <type_traits> // std::is_floating_point,std::is_integral
constexpr std::uint8_t stride = 4;
constexpr std::uint8_t size = 16;
template <typename T>
struct Mat4 {
T data[size];
// Other operators here:
Mat4 operator+(const Mat4& other) const;
// Other arithmetic operators here:
// Integral types using SSE2
template <typename U>
typename std::enable_if<std::is_integral<U>::value, Mat4<U>>::type
Mat4<T>::operator+(const Mat4& other) const {
Mat4 result;
for (std::uint8_t i = 0; i < size; i += stride) {
__m128i a = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&data[i]));
__m128i b = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&other.data[i]));
__m128i c = _mm_add_epi32(a, b); // Change this to _mm_add_epi64 for 64-bit integers
_mm_storeu_si128(reinterpret_cast<__m128i*>(&result.data[i]), c);
}
return result;
}
// Other Integer Type arithmetic operators here.
};
// Specialization for floating-point types
template <>
Mat4<float> Mat4<float>::operator+(const Mat4& other) const {
Mat4 result;
for (std::uint8_t i = 0; i < size; i += stride) {
__m128 a = _mm_loadu_ps(&data[i]);
__m128 b = _mm_loadu_ps(&other.data[i]);
__m128 c = _mm_add_ps(a, b);
_mm_storeu_ps(&result.data[i], c);
}
return result;
}
// Other floating-point type specialization arithmetic operators here
</code>
<code>#include <algorithm> // std::clamp #include <cstdint> // std::uint8_t #include <immintrin.h> // SSE/SSE2 intrinsics #include <type_traits> // std::is_floating_point,std::is_integral constexpr std::uint8_t stride = 4; constexpr std::uint8_t size = 16; template <typename T> struct Mat4 { T data[size]; // Other operators here: Mat4 operator+(const Mat4& other) const; // Other arithmetic operators here: // Integral types using SSE2 template <typename U> typename std::enable_if<std::is_integral<U>::value, Mat4<U>>::type Mat4<T>::operator+(const Mat4& other) const { Mat4 result; for (std::uint8_t i = 0; i < size; i += stride) { __m128i a = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&data[i])); __m128i b = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&other.data[i])); __m128i c = _mm_add_epi32(a, b); // Change this to _mm_add_epi64 for 64-bit integers _mm_storeu_si128(reinterpret_cast<__m128i*>(&result.data[i]), c); } return result; } // Other Integer Type arithmetic operators here. }; // Specialization for floating-point types template <> Mat4<float> Mat4<float>::operator+(const Mat4& other) const { Mat4 result; for (std::uint8_t i = 0; i < size; i += stride) { __m128 a = _mm_loadu_ps(&data[i]); __m128 b = _mm_loadu_ps(&other.data[i]); __m128 c = _mm_add_ps(a, b); _mm_storeu_ps(&result.data[i], c); } return result; } // Other floating-point type specialization arithmetic operators here </code>
#include <algorithm>    // std::clamp
#include <cstdint>      // std::uint8_t
#include <immintrin.h>  // SSE/SSE2 intrinsics
#include <type_traits>  // std::is_floating_point,std::is_integral

constexpr std::uint8_t stride = 4;
constexpr std::uint8_t size = 16;

template <typename T>
struct Mat4 {
    T data[size];

    // Other operators here:

    Mat4 operator+(const Mat4& other) const;
    // Other arithmetic operators here:
     
    // Integral types using SSE2
    template <typename U>
    typename std::enable_if<std::is_integral<U>::value, Mat4<U>>::type 
    Mat4<T>::operator+(const Mat4& other) const {
        Mat4 result;
        for (std::uint8_t i = 0; i < size; i += stride) {
            __m128i a = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&data[i]));
            __m128i b = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&other.data[i]));
            __m128i c = _mm_add_epi32(a, b);  // Change this to _mm_add_epi64 for 64-bit integers
            _mm_storeu_si128(reinterpret_cast<__m128i*>(&result.data[i]), c);
        }
        return result;
    }

    // Other Integer Type arithmetic operators here.

};

// Specialization for floating-point types
template <>
Mat4<float> Mat4<float>::operator+(const Mat4& other) const {
    Mat4 result;
    for (std::uint8_t i = 0; i < size; i += stride) {
        __m128 a = _mm_loadu_ps(&data[i]);
        __m128 b = _mm_loadu_ps(&other.data[i]);
        __m128 c = _mm_add_ps(a, b);
        _mm_storeu_ps(&result.data[i], c);
    }
    return result;
}

// Other floating-point type specialization arithmetic operators here 

I even attempted to switch the compiler to MSVC and was getting a similar compiler error but still no success, and eventually I reverted back to GCC.

12

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật