Skip to content

Commit

Permalink
Merge pull request #107 from andreasfertig/fixIssue106
Browse files Browse the repository at this point in the history
Fix issue106
  • Loading branch information
andreasfertig authored Jan 9, 2019
2 parents 3b6d20b + 8d96235 commit afb5024
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
26 changes: 19 additions & 7 deletions CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1094,21 +1094,33 @@ void CodeGenerator::InsertArg(const CXXNewExpr* stmt)
});
}

Dump(stmt);
Dump(stmt->getOperatorNew());

if(const auto* ctorExpr = stmt->getConstructExpr()) {
InsertArg(ctorExpr);

} else {
mOutputFormatHelper.Append(GetName(stmt->getAllocatedType()));
auto name = GetName(stmt->getAllocatedType());

// Special handling for arrays. They differ from one to more dimensions.
if(stmt->isArray()) {
mOutputFormatHelper.Append('[');
InsertArg(stmt->getArraySize());
mOutputFormatHelper.Append(']');
OutputFormatHelper ofm{};
CodeGenerator codeGenerator{ofm};

ofm.Append("[");
codeGenerator.InsertArg(stmt->getArraySize());
ofm.Append(']');

// In case of multi dimension the first dimension is the getArraySize() while the others are part of the
// type included in GetName(...).
if(std::string::npos != name.find("[", 0)) {
InsertBefore(name, "[", ofm.GetString());
} else {
// here we have the single dimension case, the dimension is not part of GetName, so add it.
name.append(ofm.GetString());
}
}

mOutputFormatHelper.Append(name);

if(stmt->hasInitializer()) {
InsertCurlysIfRequired(stmt->getInitializer());
}
Expand Down
5 changes: 4 additions & 1 deletion InsightsHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,10 @@ std::string GetTypeNameAsParameter(const QualType& t, const std::string& varName
{
const bool isFunctionPointer = TestPlainSubType<LValueReferenceType, FunctionProtoType>(t);
const bool isArrayRef = TestPlainSubType<LValueReferenceType, ConstantArrayType>(t);
const bool isPointerToArray = TestPlainSubType<PointerType, ConstantArrayType>(t);
// Special case for Issue81, auto returns an array-ref and to catch auto deducing an array (Issue106)
const bool isAutoType = dyn_cast_or_null<AutoType>(t.getTypePtrOrNull());
const auto pointerToArrayBaseType = isAutoType ? t->getContainedAutoType()->getDeducedType() : t;
const bool isPointerToArray = TestPlainSubType<PointerType, ConstantArrayType>(pointerToArrayBaseType);

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

Expand Down
9 changes: 9 additions & 0 deletions tests/Issue106.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
int main()
{
auto p = new int[2][3][4];

// auto z = new int[1];

// auto x = new int;
}

6 changes: 6 additions & 0 deletions tests/Issue106.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int main()
{
int (*p)[3][4] = new int [2][3][4];
}


0 comments on commit afb5024

Please sign in to comment.