@@ -2109,7 +2109,7 @@ bool template_compare(std::string n1, std::string n2) {
21092109}
21102110
21112111Cppyy::TCppMethod_t Cppyy::GetMethodTemplate (TCppScope_t scope, const std::string &name, const std::string &proto,
2112- std::ostream &diagnostics)
2112+ std::ostringstream &diagnostics)
21132113{
21142114// There is currently no clean way of extracting a templated method out of ROOT/meta
21152115// for a variety of reasons, none of them fundamental. The game played below is to
@@ -2127,6 +2127,7 @@ Cppyy::TCppMethod_t Cppyy::GetMethodTemplate(TCppScope_t scope, const std::strin
21272127// redirect diagnostics, taking the lock to make sure no other calls pollute the results
21282128 R__WRITE_LOCKGUARD (ROOT ::gCoreMutex );
21292129
2130+ const std::string diagnosticsold = diagnostics.str ();
21302131 TInterpreter::RedirectDiagnostics redirectRAII (gInterpreter , diagnostics, /* enableColors*/ true , /* indent*/ 4 );
21312132
21322133 TFunction *func = nullptr ;
@@ -2162,15 +2163,25 @@ Cppyy::TCppMethod_t Cppyy::GetMethodTemplate(TCppScope_t scope, const std::strin
21622163
21632164 if (!func && name.back () == ' >' && (cl || scope == (TCppScope_t)GLOBAL_HANDLE )) {
21642165 // try again, ignoring proto in case full name is complete template
2165- auto declid = gInterpreter ->GetFunction (cl, name.c_str ());
2166- if (declid) {
2167- auto existing = gMethodTemplates .find (declid);
2168- if (existing == gMethodTemplates .end ()) {
2169- auto cw = new_CallWrapper (declid, name);
2170- existing = gMethodTemplates .insert (std::make_pair (declid, cw)).first ;
2171- }
2172- return (TCppMethod_t)existing->second ;
2166+ std::ostringstream diagnostics2;
2167+ TInterpreter::RedirectDiagnostics redirectRAII2 (gInterpreter , diagnostics2, /* enableColors*/ true , /* indent*/ 4 );
2168+
2169+ auto declid = gInterpreter ->GetFunction (cl, name.c_str ());
2170+ if (declid) {
2171+ auto existing = gMethodTemplates .find (declid);
2172+ if (existing == gMethodTemplates .end ()) {
2173+ auto cw = new_CallWrapper (declid, name);
2174+ existing = gMethodTemplates .insert (std::make_pair (declid, cw)).first ;
2175+ }
2176+ // replace diagnostics to suppress spurious errors or warnings from the previous
2177+ // failed lookup
2178+ diagnostics = std::ostringstream ();
2179+ diagnostics << diagnosticsold;
2180+ diagnostics << diagnostics2.str ();
2181+
2182+ return (TCppMethod_t)existing->second ;
21732183 }
2184+ diagnostics << diagnostics2.str ();
21742185 }
21752186
21762187 if (func) {
@@ -2186,13 +2197,20 @@ Cppyy::TCppMethod_t Cppyy::GetMethodTemplate(TCppScope_t scope, const std::strin
21862197 if (name.back () == ' >' ) {
21872198 auto pos = name.find (' <' );
21882199 if (pos != std::string::npos) {
2189- TCppMethod_t cppmeth = GetMethodTemplate (scope, name.substr (0 , pos), proto, diagnostics );
2200+ TCppMethod_t cppmeth = GetMethodTemplate (scope, name.substr (0 , pos), proto, diagnostics2 );
21902201 if (cppmeth) {
21912202 // allow if requested template names match up to the result
21922203 const std::string& alt = GetMethodFullName (cppmeth);
21932204 if (name.size () < alt.size () && alt.find (' <' ) == pos) {
2194- if (template_compare (name, alt))
2205+ if (template_compare (name, alt)){
2206+ // replace diagnostics to suppress spurious errors or warnings
2207+ // from the previous failed lookup
2208+ diagnostics = std::ostringstream ();
2209+ diagnostics << diagnosticsold;
2210+ diagnostics << diagnostics2.str ();
21952211 return cppmeth;
2212+ }
2213+
21962214 }
21972215 }
21982216 }
0 commit comments