Skip to content

explicit specialization in non-namespace scope #2614

@ferdymercury

Description

@ferdymercury

Describe the Bug:
Compilation error due to code that violates C++ standard


/opt/oneDPL/include/oneapi/dpl/internal/random_impl/normal_distribution.h:265:15: error: explicit specialization in non-namespace scope ‘class oneapi::dpl::normal_distribution<_RealType>’
  265 |     template <>
      |               ^
/opt/oneDPL/include/oneapi/dpl/internal/random_impl/normal_distribution.h:267:5: error: template-id ‘callback<double>’ in declaration of primary template
  267 |     callback<double>()
      |     ^~~~~~~~~~~~~~~~
/opt/oneDPL/include/oneapi/dpl/internal/random_impl/normal_distribution.h:280:15: error: explicit specialization in non-namespace scope ‘class oneapi::dpl::normal_distribution<_RealType>’
  280 |     template <>
      |               ^
/opt/oneDPL/include/oneapi/dpl/internal/random_impl/normal_distribution.h:282:5: error: template-id ‘pi2<double>’ in declaration of primary template
  282 |     pi2<double>()
      |     ^~~~~~~~~~~

To Reproduce:

From eg a g++ compiler, just include

#include "/opt/oneDPL/include/oneapi/dpl/internal/random_impl/random_common.h"
#include "/opt/oneDPL/include/oneapi/dpl/internal/random_impl/uniform_real_distribution.h"
#include "/opt/oneDPL/include/oneapi/dpl/internal/random_impl/normal_distribution.h"

and try to compile in debug mode.

Expected Behavior:
Code follows C++ standard.

My current workaround is to just comment out by hand

template <>
    inline scalar_type
    callback<double>()

and

template <>
    inline scalar_type
    pi2<double>()

then it compiles just fine.

Additional Context:
It seems MSVC is relaxed in this respect, but not other compilers when in Debug mode (even if I do not call those functions).

https://stackoverflow.com/questions/2097811/c-syntax-for-explicit-specialization-of-a-template-function-in-a-template-clas
https://stackoverflow.com/questions/49707184/explicit-specialization-in-non-namespace-scope-does-not-compile-in-gcc
https://stackoverflow.com/questions/3052579/explicit-specialization-in-non-namespace-scope

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions