Skip to content

error: explicit specialization in non-namespace scope #3

Description

@dromer

Ran into this using gcc 14.2.0:

/home/dreamer/Sources/_projects/_pgm/PGM-App/build/_deps/signalsmith-linear-src/include/signalsmith-linear/../../linear.h:1055:18: error: explicit specialization in non-namespace scope ‘struct signalsmith::linear::LinearImpl<<anonymous> >’
 1055 |         template<>
      |                  ^
/home/dreamer/Sources/_projects/_pgm/PGM-App/build/_deps/signalsmith-linear-src/include/signalsmith-linear/../../linear.h:1056:14: error: template-id ‘reserve<float>’ in declaration of primary template
 1056 |         void reserve<float>(size_t size) {
      |              ^~~~~~~~~~~~~~
/home/dreamer/Sources/_projects/_pgm/PGM-App/build/_deps/signalsmith-linear-src/include/signalsmith-linear/../../linear.h:1059:18: error: explicit specialization in non-namespace scope ‘struct signalsmith::linear::LinearImpl<<anonymous> >’
 1059 |         template<>
      |                  ^
/home/dreamer/Sources/_projects/_pgm/PGM-App/build/_deps/signalsmith-linear-src/include/signalsmith-linear/../../linear.h:1060:14: error: template-id ‘reserve<double>’ in declaration of primary template
 1060 |         void reserve<double>(size_t size) {
      |              ^~~~~~~~~~~~~~~
/home/dreamer/Sources/_projects/_pgm/PGM-App/build/_deps/signalsmith-linear-src/include/signalsmith-linear/../../linear.h:1060:14: error: ‘void signalsmith::linear::LinearImpl<<anonymous> >::reserve(size_t)’ cannot be overloaded with ‘void signalsmith::linear::LinearImpl<<anonymous> >::reserve(size_t)’
/home/dreamer/Sources/_projects/_pgm/PGM-App/build/_deps/signalsmith-linear-src/include/signalsmith-linear/../../linear.h:1056:14: note: previous declaration ‘void signalsmith::linear::LinearImpl<<anonymous> >::reserve(size_t)’
 1056 |         void reserve<float>(size_t size) {
      |              ^~~~~~~~~~~~~~

Quick fix was this:

        template<typename V>
-       void reserve(size_t) {}
-       // Makes sure we don't allocate
-       template<>
-       void reserve<float>(size_t size) {
-               cached.reserveFloats(size);
-       }
-       template<>
-       void reserve<double>(size_t size) {
-               cached.reserveDoubles(size);
+       void reserve(size_t size) {
+               // Makes sure we don't allocate
+               if constexpr (std::is_same<V, float>::value) {
+                       cached.reserveFloats(size);
+               } else if constexpr (std::is_same<V, double>::value) {
+                       cached.reserveDoubles(size);
+               }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions