diff --git a/core/metacling/test/TClingCallFuncTests.cxx b/core/metacling/test/TClingCallFuncTests.cxx index d813cb1d0b413..31b471da8f916 100644 --- a/core/metacling/test/TClingCallFuncTests.cxx +++ b/core/metacling/test/TClingCallFuncTests.cxx @@ -1,3 +1,5 @@ +#include "ROOT/RStringView.hxx" +#include "TError.h" #include "TInterpreter.h" #include "gtest/gtest.h" @@ -14,6 +16,19 @@ // system, feel free to delete them as these tests here don't represent things the user // should do in his code. +class FilterDiagsRAII { + ErrorHandlerFunc_t fPrevHandler; +public: + FilterDiagsRAII(ErrorHandlerFunc_t fn) : fPrevHandler(::GetErrorHandler()) { + ::SetErrorHandler(fn); + gInterpreter->ReportDiagnosticsToErrorHandler(); + } + ~FilterDiagsRAII() { + gInterpreter->ReportDiagnosticsToErrorHandler(/*enable=*/false); + ::SetErrorHandler(fPrevHandler); + } +}; + TEST(TClingCallFunc, FunctionWrapper) { gInterpreter->Declare(R"cpp( @@ -259,3 +274,33 @@ TEST(TClingCallFunc, DISABLED_OverloadedTemplate) } )cpp"); } + +TEST(TClingCallFunc, FunctionWrapperNodiscard) +{ + gInterpreter->Declare(R"cpp( + #if __cplusplus >= 201703L + [[nodiscard]] + #endif + bool FunctionWrapperNodiscard(int) { return false; } + )cpp"); + + ClassInfo_t *GlobalNamespace = gInterpreter->ClassInfo_Factory(""); + CallFunc_t *mc = gInterpreter->CallFunc_Factory(); + Longptr_t offset = 0; + + gInterpreter->CallFunc_SetFuncProto(mc, GlobalNamespace, "FunctionWrapperNodiscard", "int", &offset); + std::string wrapper = gInterpreter->CallFunc_GetWrapperCode(mc); + + { + FilterDiagsRAII RAII([] (int /*level*/, Bool_t /*abort*/, + const char * /*location*/, const char *msg) { + if (std::string_view(msg).find("-Wunused-result") != std::string_view::npos) + FAIL() << "Should not emit '-Wunused-result' diagnostic"; + }); + ASSERT_TRUE(gInterpreter->Declare(wrapper.c_str())); + } + + // Cleanup + gInterpreter->CallFunc_Delete(mc); + gInterpreter->ClassInfo_Delete(GlobalNamespace); +}