diff options
author | Luca Di Sera <disera.luca@gmail.com> | 2022-09-02 09:54:10 -0400 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2022-09-02 09:54:10 -0400 |
commit | e7d9917a60dca60da05d0114de9858ed7acb015c (patch) | |
tree | 8bc207228ae433dd4b74af4f985ab22f6f0a8fa3 /clang/unittests/libclang/LibclangTest.cpp | |
parent | 3224cf8b31f1b5bcc156b5ce63e1fcec1a6c305f (diff) | |
download | llvm-e7d9917a60dca60da05d0114de9858ed7acb015c.zip llvm-e7d9917a60dca60da05d0114de9858ed7acb015c.tar.gz llvm-e7d9917a60dca60da05d0114de9858ed7acb015c.tar.bz2 |
Expose QualType::getNonReferenceType in libclang
The method is now wrapped by clang_getNonReferenceType.
A declaration for clang_getNonReferenceType was added to clang-c/Index.h
to expose it to user of the library.
An implementation for clang_getNonReferenceType was introduced in
CXType.cpp, wrapping the equivalent method of the underlying QualType of
a CXType.
An export symbol for the new function was added to libclang.map under
the LLVM_16 version entry.
A test was added to LibclangTest.cpp that tests the removal of
ref-qualifiers for some CXTypes.
The release-notes for the clang project was updated to include a
notification of the new addition under the "libclang" section.
Differential Revision: https://reviews.llvm.org/D133195
Diffstat (limited to 'clang/unittests/libclang/LibclangTest.cpp')
-rw-r--r-- | clang/unittests/libclang/LibclangTest.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/clang/unittests/libclang/LibclangTest.cpp b/clang/unittests/libclang/LibclangTest.cpp index e608485..d020fa9 100644 --- a/clang/unittests/libclang/LibclangTest.cpp +++ b/clang/unittests/libclang/LibclangTest.cpp @@ -891,6 +891,46 @@ TEST_F(LibclangParseTest, clang_getUnqualifiedTypeRemovesQualifiers) { }); } +TEST_F(LibclangParseTest, clang_getNonReferenceTypeRemovesRefQualifiers) { + std::string Header = "header.h"; + WriteFile(Header, "void foo1(int&);\n" + "void foo2(int&&);\n"); + + auto is_ref_qualified = [](CXType type) -> bool { + return (type.kind == CXType_LValueReference) || + (type.kind == CXType_RValueReference); + }; + + auto from_CXString = [](CXString cx_string) -> std::string { + std::string string{clang_getCString(cx_string)}; + + clang_disposeString(cx_string); + + return string; + }; + + const char *Args[] = {"-xc++"}; + ClangTU = clang_parseTranslationUnit(Index, Header.c_str(), Args, 1, nullptr, + 0, TUFlags); + + Traverse([&is_ref_qualified, &from_CXString](CXCursor cursor, CXCursor) { + if (clang_getCursorKind(cursor) == CXCursor_FunctionDecl) { + CXType arg_type = clang_getArgType(clang_getCursorType(cursor), 0); + EXPECT_TRUE(is_ref_qualified(arg_type)) + << "Input data '" << from_CXString(clang_getCursorSpelling(cursor)) + << "' first argument does not have a ref-qualified type."; + + CXType non_reference_arg_type = clang_getNonReferenceType(arg_type); + EXPECT_FALSE(is_ref_qualified(non_reference_arg_type)) + << "The type '" << from_CXString(clang_getTypeSpelling(arg_type)) + << "' ref-qualifier was not removed after a call to " + "clang_getNonReferenceType."; + } + + return CXChildVisit_Continue; + }); +} + class LibclangRewriteTest : public LibclangParseTest { public: CXRewriter Rew = nullptr; |