diff --git a/core/metacling/src/TClingCallbacks.cxx b/core/metacling/src/TClingCallbacks.cxx index d8ce47ba40196..2be13f2865373 100644 --- a/core/metacling/src/TClingCallbacks.cxx +++ b/core/metacling/src/TClingCallbacks.cxx @@ -33,6 +33,7 @@ #include "clang/Sema/Scope.h" #include "clang/Serialization/ASTReader.h" #include "clang/Serialization/GlobalModuleIndex.h" +#include "clang/Basic/DiagnosticSema.h" #include "llvm/ExecutionEngine/Orc/Core.h" @@ -1004,6 +1005,12 @@ bool TClingCallbacks::tryInjectImplicitAutoKeyword(LookupResult &R, Scope *S) { Result->addAttr(AnnotateAttr::CreateImplicit(C, "__Auto")); R.addDecl(Result); + + // Raise a warning when trying to use implicit auto injection feature. + SemaRef.getDiagnostics().setSeverity(diag::warn_deprecated_message, diag::Severity::Warning, SourceLocation()); + SemaRef.Diag(Loc, diag::warn_deprecated_message) + << "declaration without the 'auto' keyword" << DC << Loc << FixItHint::CreateInsertion(Loc, "auto "); + // Say that we can handle the situation. Clang should try to recover return true; } diff --git a/core/metacling/test/TClingTests.cxx b/core/metacling/test/TClingTests.cxx index 329938de9ea49..b94656864f66c 100644 --- a/core/metacling/test/TClingTests.cxx +++ b/core/metacling/test/TClingTests.cxx @@ -239,6 +239,19 @@ TEST_F(TClingTests, GetSharedLibDeps) } #endif +// Check that a warning message is generated when using auto-injection. +TEST_F(TClingTests, WarningAutoInjection) +{ + ROOT::TestSupport::CheckDiagsRAII diags; + diags.requiredDiag(kWarning, "cling", "declaration without the 'auto' keyword is deprecated", + /*matchFullMessage=*/false); + + gInterpreter->ProcessLine("/* no auto */ t = new int;"); + + auto t = gInterpreter->GetDataMember(nullptr, "t"); + EXPECT_TRUE(t != nullptr); +} + // Check the interface which interacts with the cling::LookupHelper. TEST_F(TClingTests, ClingLookupHelper) { // Exception spec evaluation.