Skip to content

Commit

Permalink
Merge pull request #545 from andreasfertig/fixIssue543
Browse files Browse the repository at this point in the history
Fixed #543: Include variable name of an array with a typdef or using.
  • Loading branch information
andreasfertig authored Jun 21, 2023
2 parents 7941e71 + e2fbaf8 commit 6720a43
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 2 deletions.
7 changes: 5 additions & 2 deletions InsightsHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,9 @@ std::string GetTypeNameAsParameter(const QualType& t, std::string_view varName,
const bool isAutoType = (nullptr != dyn_cast_or_null<AutoType>(t.getTypePtrOrNull()));
const auto pointerToArrayBaseType = isAutoType ? t->getContainedAutoType()->getDeducedType() : t;
const bool isPointerToArray = HasTypeWithSubType<PointerType, ArrayType>(pointerToArrayBaseType);
// Only treat this as an array if it is a top-level arry. Typdef's et all can hide the arrayness.
const bool isRawArrayType =
t->isArrayType() and not(isa<TypedefType>(t) or isa<ElaboratedType>(t) or isa<UsingType>(t));

std::string typeName = details::GetName(t, unqualified);

Expand All @@ -1053,7 +1056,7 @@ std::string GetTypeNameAsParameter(const QualType& t, std::string_view varName,
return {};
};

if(t->isArrayType() and not t->isLValueReferenceType()) {
if(isRawArrayType and not t->isLValueReferenceType()) {
const auto space = getSpaceOrEmpty(" ["sv);
InsertBefore(typeName, "["sv, StrCat(space, varName));

Expand Down Expand Up @@ -1113,7 +1116,7 @@ std::string GetTypeNameAsParameter(const QualType& t, std::string_view varName,
typeName += StrCat(" "sv, varName);
}

} else if(not t->isArrayType() and not varName.empty()) {
} else if(not isRawArrayType and not varName.empty()) {
typeName += StrCat(" "sv, varName);
}

Expand Down
13 changes: 13 additions & 0 deletions tests/ArrayInTypedefTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace test {
typedef int jmp_buf[30];

jmp_buf a;
}


test::jmp_buf x;


using test::jmp_buf;

jmp_buf t;
16 changes: 16 additions & 0 deletions tests/ArrayInTypedefTest.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace test
{
using jmp_buf = int[30];
jmp_buf a;

}


test::jmp_buf x;



using test::jmp_buf;

test::jmp_buf t;

21 changes: 21 additions & 0 deletions tests/Issue543.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <cstdio>
#include <csetjmp>
std::jmp_buf jump_buffer;

void foo() {
printf("foo: Entered\n");
longjmp(jump_buffer, 1); // Jump back to where setjmp was called
printf("foo: This won't be executed\n");
}

int main() {
if (setjmp(jump_buffer) == 0) {
printf("main: Calling foo\n");
foo();
} else {
printf("main: Jumped back from foo\n");
}

printf("main: Exiting\n");
return 0;
}
26 changes: 26 additions & 0 deletions tests/Issue543.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <cstdio>
#include <csetjmp>
std::jmp_buf jump_buffer;


void foo()
{
printf("foo: Entered\n");
longjmp(jump_buffer, 1);
printf("foo: This won't be executed\n");
}


int main()
{
if(setjmp(jump_buffer) == 0) {
printf("main: Calling foo\n");
foo();
} else {
printf("main: Jumped back from foo\n");
}

printf("main: Exiting\n");
return 0;
}

0 comments on commit 6720a43

Please sign in to comment.