Skip to content

Commit

Permalink
[tcling] Add test against issue #8622
Browse files Browse the repository at this point in the history
  • Loading branch information
jalopezg-git committed Nov 5, 2021
1 parent 0d34ed1 commit 8993573
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions core/metacling/test/TClingCallFuncTests.cxx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "ROOT/RStringView.hxx"
#include "TError.h"
#include "TInterpreter.h"

#include "gtest/gtest.h"
Expand All @@ -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(
Expand Down Expand Up @@ -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);
}

0 comments on commit 8993573

Please sign in to comment.