From 788abfa8a49022d6e6e783cb1ea3e94403064876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 24 Nov 2020 19:20:16 +0100 Subject: [PATCH] Clang import: better handling of CXXMethodDecl in getSpelling --- lib/clangimport.cpp | 2 +- test/testclangimport.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 662a9a306..c17c5543a 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -347,7 +347,7 @@ std::string clangimport::AstNode::getSpelling() const } int typeIndex = mExtTokens.size() - 1; - if (nodeType == FunctionDecl || nodeType == CXXConstructorDecl) { + if (nodeType == FunctionDecl || nodeType == CXXConstructorDecl || nodeType == CXXMethodDecl) { while (typeIndex >= 0 && mExtTokens[typeIndex][0] != '\'') typeIndex--; if (typeIndex <= 0) diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index e382c7a39..3322a9d8e 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -56,6 +56,7 @@ private: TEST_CASE(cxxMethodDecl1); TEST_CASE(cxxMethodDecl2); TEST_CASE(cxxMethodDecl3); + TEST_CASE(cxxMethodDecl4); TEST_CASE(cxxNewExpr1); TEST_CASE(cxxNewExpr2); TEST_CASE(cxxNullPtrLiteralExpr); @@ -508,6 +509,20 @@ private: ASSERT_EQUALS("class Fred { void foo ( ) ; } ; void Fred :: foo ( ) { }", parse(clang)); } + void cxxMethodDecl4() { + const char clang[] = "|-ClassTemplateSpecializationDecl 0x15d82f8 line:8:12 struct char_traits definition\n" + "| |-TemplateArgument type 'char'\n" + "| | `-BuiltinType 0x15984c0 'char'\n" + "| |-CXXRecordDecl 0x15d8520 col:12 implicit struct char_traits\n" + "| |-TypedefDecl 0x15d85c0 col:20 referenced char_type 'char'\n" + "| | `-BuiltinType 0x15984c0 'char'\n" + "| |-CXXMethodDecl 0x15d8738 line:13:7 move 'char *(char *)' static\n" + "| | |-ParmVarDecl 0x15d8630 col:18 used __s1 'char *'\n" + "| | `-CompoundStmt 0x15d88e8 \n"; + ASSERT_EQUALS("struct char_traits { static char * move ( char * __s1@1 ) { } } ;", + parse(clang)); + } + void cxxNewExpr1() { const char clang[] = "|-VarDecl 0x3a97680 <1.cpp:2:1, col:14> col:6 i 'int *' cinit\n" "| `-CXXNewExpr 0x3a97d18 'int *' Function 0x3a97778 'operator new' 'void *(unsigned long)'\n"