diff --git a/core/metacling/test/TClingTests.cxx b/core/metacling/test/TClingTests.cxx index 2a54d12864dd3..ec9833264f82e 100644 --- a/core/metacling/test/TClingTests.cxx +++ b/core/metacling/test/TClingTests.cxx @@ -467,4 +467,23 @@ using func0_ret_t = typename ROOT::TypeTraits::CallableTraits:: auto res = gInterpreter->Declare(expression.c_str()); EXPECT_TRUE(res); } -#endif \ No newline at end of file +#endif + +// ROOT-10311 +TEST_F(TClingTests, TClassByCtorName) +{ + auto res = gInterpreter->Declare("namespace TClassByCtorName{class Foo;};"); + EXPECT_TRUE(res); + { + ROOT::TestSupport::CheckDiagsRAII checkDiag; + checkDiag.requiredDiag(kWarning, "TClass::Init", "no dictionary for class TClassByCtorName::Foo is available", false); + EXPECT_TRUE(nullptr != TClass::GetClass("TClassByCtorName::Foo")); + } + const auto *wrongName = "TTree::TTree"; + EXPECT_TRUE(nullptr == TClass::GetClass(wrongName)); + EXPECT_TRUE(nullptr != TClass::GetClass("TTree")); + + std::string classInterpreterName; + gInterpreter->GetInterpreterTypeName(wrongName, classInterpreterName); + EXPECT_STREQ(classInterpreterName.c_str(), ""); +} diff --git a/interpreter/cling/lib/Interpreter/LookupHelper.cpp b/interpreter/cling/lib/Interpreter/LookupHelper.cpp index 499c9f0631174..1a6433cfd9761 100644 --- a/interpreter/cling/lib/Interpreter/LookupHelper.cpp +++ b/interpreter/cling/lib/Interpreter/LookupHelper.cpp @@ -294,6 +294,14 @@ namespace cling { next = utils::Lookup::Named(&S, declName.substr(last, c + 1 - last), sofar); // If there is an ambiguity, we need to go the long route. if (next == (void *) -1) return false; + if (const auto *RD = dyn_cast_or_null(next); + RD && RD->isInjectedClassName()) { + // We found an injected-class-name, which is not a scope. + // See [class.qual]p2. Not skipping the injected-class-name, would + // lead to a wrong lookup result for "C::C" where C is a class name. + resultDecl = nullptr; + return true; // nothing found + } if (next) { resultDecl = next; }