Skip to content

PyROOT/cppyy fails with template functions overload with SFINAE #15085

@VanyaBelyaev

Description

@VanyaBelyaev

Check duplicate issues.

  • Checked for duplicates

Description

Recent version of PyROOT/cppyy fails for relatively simple templated function overload with SFINAE. The reproducer is here.
There is templated C++ class A
and there are template functions fun_2 overloaded with SFINAE - see below.

For completeness:

  • for templated member functions SFINAE overload works ok.. [It was not the case for relatively old PyROOT/cppyy

I am using LCG-dev3 cvmfs nightly builds with ROOT 6.31/01

Reproducer

import ROOT
print ( 'ROOT version' , ROOT.gROOT.GetVersion() )
ROOT.gInterpreter.Declare('''
#include <type_traits> 
#include <string> 
template <unsigned int  N>
class A
{
public:
//
template <unsigned int K,
typename std::enable_if<(K<N),int>::type = 0 >
std::string fun_1 () { return "ququ" ;} 
//
template <unsigned int K,
typename std::enable_if<(N<=K),int>::type = 0 >
int         fun_1 () { return K ;} 
};
// the same with functions
template <unsigned int K,unsigned int N, 
typename std::enable_if<(K<N),int>::type = 0 >
inline std::string fun_2 ( A<N>& ) { return "ququ" ;} 
//
template <unsigned int K,unsigned int N,
typename std::enable_if<(N<=K),int>::type = 0 >
inline int         fun_2 ( A<N>& ) { return K ;} 
''')

N = 4 
a = ROOT.A [ N ]()

print ( 'Use templated method of templated class A<4> : it is OK ' ) 
for k in range ( 2 * N + 1 ) : 
    print  ( k , a.fun_1[k]() ) 

print ( 'Use templated function for templated class A<4> : it fails for k >=4' ) 
for k in range( 2 * N + 1  ) :
    func = ROOT.fun_2[k,N]
    print  ( k , func ( a )  ) 

And the output is:

ROOT version 6.31/01
Use templated method of templated class A<4> : it is OK
0 ququ
1 ququ
2 ququ
3 ququ
4 4
5 5
6 6
7 7
8 8
Use templated function for templated class A<4> : it fails for k >=4
0 ququ
1 ququ
2 ququ
3 ququ
Traceback (most recent call last):
  File "/afs/cern.ch/user/i/ibelyaev/cmtuser/RELEASE/ostap/build/./tst64.py", line 44, in <module>
    print  ( k , func ( a )  )
TypeError: Could not find "fun_2<4,4>" (set cppyy.set_debug() for C++ errors):
  Failed to instantiate "fun_2<4,4>(A<4>&)"

ROOT version

6.31/01
Linux,
LCG-dev3 cvmvs nightly builds

Installation method

LCG-dev3 cvmfs nightly build

Operating system

Linux

Additional context

If I am not mistaken semtime ago the situations was just an opposite - stanalone template fuctions were OK, but template methods were not OK... but now I am not 100% sure...

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions