@@ -1837,7 +1837,7 @@ bool Cppyy::IsMethodTemplate(TCppScope_t scope, TCppIndex_t idx)
18371837static std::map<TDictionary::DeclId_t, CallWrapper*> gMethodTemplates ;
18381838
18391839Cppyy::TCppMethod_t Cppyy::GetMethodTemplate (TCppScope_t scope, const std::string &name, const std::string &proto,
1840- std::ostream &diagnostics)
1840+ std::ostringstream &diagnostics)
18411841{
18421842// There is currently no clean way of extracting a templated method out of ROOT/meta
18431843// for a variety of reasons, none of them fundamental. The game played below is to
@@ -1854,6 +1854,7 @@ Cppyy::TCppMethod_t Cppyy::GetMethodTemplate(TCppScope_t scope, const std::strin
18541854// redirect diagnostics, taking the lock to make sure no other calls pollute the results
18551855R__WRITE_LOCKGUARD (ROOT ::gCoreMutex );
18561856
1857+ const std::string diagnosticsold = diagnostics.str ();
18571858TInterpreter::RedirectDiagnostics redirectRAII (gInterpreter , diagnostics, /* enableColors*/ true , /* indent*/ 4 );
18581859
18591860TFunction *func = nullptr ;
@@ -1885,15 +1886,25 @@ if (scope == (cppyy_scope_t)GLOBAL_HANDLE) {
18851886
18861887 if (!func && name.back () == ' >' && (cl || scope == (cppyy_scope_t )GLOBAL_HANDLE )) {
18871888 // try again, ignoring proto in case full name is complete template
1888- auto declid = gInterpreter ->GetFunction (cl, name.c_str ());
1889- if (declid) {
1890- auto existing = gMethodTemplates .find (declid);
1891- if (existing == gMethodTemplates .end ()) {
1892- auto cw = new_CallWrapper (declid, name);
1893- existing = gMethodTemplates .insert (std::make_pair (declid, cw)).first ;
1894- }
1895- return (TCppMethod_t)existing->second ;
1889+ std::ostringstream diagnostics2;
1890+ TInterpreter::RedirectDiagnostics redirectRAII2 (gInterpreter , diagnostics2, /* enableColors*/ true , /* indent*/ 4 );
1891+
1892+ auto declid = gInterpreter ->GetFunction (cl, name.c_str ());
1893+ if (declid) {
1894+ auto existing = gMethodTemplates .find (declid);
1895+ if (existing == gMethodTemplates .end ()) {
1896+ auto cw = new_CallWrapper (declid, name);
1897+ existing = gMethodTemplates .insert (std::make_pair (declid, cw)).first ;
1898+ }
1899+ // replace diagnostics to suppress spurious errors or warnings from the previous
1900+ // failed lookup
1901+ diagnostics = std::ostringstream ();
1902+ diagnostics << diagnosticsold;
1903+ diagnostics << diagnostics2.str ();
1904+
1905+ return (TCppMethod_t)existing->second ;
18961906 }
1907+ diagnostics << diagnostics2.str ();
18971908 }
18981909
18991910 if (func) {
@@ -1909,16 +1920,24 @@ if (scope == (cppyy_scope_t)GLOBAL_HANDLE) {
19091920 if (name.back () == ' >' ) {
19101921 auto pos = name.find (' <' );
19111922 if (pos != std::string::npos) {
1912- TCppMethod_t cppmeth = GetMethodTemplate (scope, name.substr (0 , pos), proto, diagnostics);
1923+ std::ostringstream diagnostics2;
1924+ TCppMethod_t cppmeth = GetMethodTemplate (scope, name.substr (0 , pos), proto, diagnostics2);
19131925 if (cppmeth) {
19141926 // allow if requested template names match up to the result
19151927 const std::string &alt = GetMethodFullName (cppmeth);
19161928 if (name.size () < alt.size () && alt.find (' <' ) == pos) {
19171929 const std::string &partial = name.substr (pos, name.size () - 1 - pos);
1918- if (strncmp (partial.c_str (), alt.substr (pos, alt.size () - 1 - pos).c_str (), partial.size ()) == 0 )
1930+ if (strncmp (partial.c_str (), alt.substr (pos, alt.size () - 1 - pos).c_str (), partial.size ()) == 0 ) {
1931+ // replace diagnostics to suppress spurious errors or warnings
1932+ // from the previous failed lookup
1933+ diagnostics = std::ostringstream ();
1934+ diagnostics << diagnosticsold;
1935+ diagnostics << diagnostics2.str ();
19191936 return cppmeth;
1937+ }
19201938 }
19211939 }
1940+ diagnostics << diagnostics2.str ();
19221941 }
19231942 }
19241943
0 commit comments