clangbackend: Categorize non-const pointer arguments as output arguments

Fixes: QTCREATORBUG-24550
Change-Id: Iac4f3b133a632d7272bfe4253f8a0740e51b0952
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2020-10-14 14:12:30 +02:00
parent cbf4e8af0a
commit ed292f3f9b
3 changed files with 20 additions and 9 deletions

View File

@@ -76,7 +76,18 @@ bool Type::isReferencingConstant() const
bool Type::isOutputArgument() const bool Type::isOutputArgument() const
{ {
return isLValueReference() && !pointeeType().isConstant(); if (isLValueReference() && !pointeeType().isConstant())
return true;
// We consider a pointer an output argument if it is non-const at any level.
// This is consistent with how we categorize references in CppTools.
Type t = *this;
while (t.isPointer()) {
t = t.pointeeType();
if (!t.isConstant())
return true;
}
return false;
} }
bool Type::isBuiltinType() const bool Type::isBuiltinType() const

View File

@@ -489,7 +489,7 @@ TEST_F(Cursor, HasOutputValues)
auto outputArgumentLocations = callExpressionCursor.outputArgumentRanges(); auto outputArgumentLocations = callExpressionCursor.outputArgumentRanges();
ASSERT_THAT(outputArgumentLocations.size(), 1); ASSERT_THAT(outputArgumentLocations.size(), 2);
ASSERT_THAT(outputArgumentLocations[0], outputArgumentExpectedSourceLocation); ASSERT_THAT(outputArgumentLocations[0], outputArgumentExpectedSourceLocation);
} }
@@ -744,13 +744,13 @@ TEST_F(Cursor, PointerIsNotRefencingConstant)
ASSERT_FALSE(argument.isReferencingConstant()); ASSERT_FALSE(argument.isReferencingConstant());
} }
TEST_F(Cursor, PointerIsNotOutputArgument) TEST_F(Cursor, PointerIsOutputArgument)
{ {
auto callExpressionCursor = translationUnit.cursorAt(127, 13); auto callExpressionCursor = translationUnit.cursorAt(127, 13);
auto argument = callExpressionCursor.type().argument(0); auto argument = callExpressionCursor.type().argument(0);
ASSERT_FALSE(argument.isOutputArgument()); ASSERT_TRUE(argument.isOutputArgument());
} }
TEST_F(Cursor, ConstantReferenceIsNotOutputArgument) TEST_F(Cursor, ConstantReferenceIsNotOutputArgument)
@@ -771,13 +771,13 @@ TEST_F(Cursor, PointerToConstantIsNotOutputArgument)
ASSERT_FALSE(argument.isOutputArgument()) << argument.isConstant() << argument.pointeeType().isConstant(); ASSERT_FALSE(argument.isOutputArgument()) << argument.isConstant() << argument.pointeeType().isConstant();
} }
TEST_F(Cursor, ConstantPointerIsNotOutputArgument) TEST_F(Cursor, ConstantPointerIsOutputArgument)
{ {
auto callExpressionCursor = translationUnit.cursorAt(128, 21); auto callExpressionCursor = translationUnit.cursorAt(128, 21);
auto argument = callExpressionCursor.type().argument(0); auto argument = callExpressionCursor.type().argument(0);
ASSERT_FALSE(argument.isOutputArgument()); ASSERT_TRUE(argument.isOutputArgument());
} }
TEST_F(Cursor, ReferenceIsOutputArgument) TEST_F(Cursor, ReferenceIsOutputArgument)

View File

@@ -1326,7 +1326,7 @@ TEST_F(TokenProcessor, NonConstPointerArgument)
infos[1]; infos[1];
ASSERT_THAT(infos[2], ASSERT_THAT(infos[2],
HasOnlyType(HighlightingType::LocalVariable)); HasTwoTypes(HighlightingType::LocalVariable, HighlightingType::OutputArgument));
} }
TEST_F(TokenProcessor, PointerToConstArgument) TEST_F(TokenProcessor, PointerToConstArgument)
@@ -1346,7 +1346,7 @@ TEST_F(TokenProcessor, ConstPointerArgument)
infos[1]; infos[1];
ASSERT_THAT(infos[2], ASSERT_THAT(infos[2],
HasOnlyType(HighlightingType::LocalVariable)); HasTwoTypes(HighlightingType::LocalVariable, HighlightingType::OutputArgument));
} }
TEST_F(TokenProcessor, NonConstPointerGetterAsArgument) TEST_F(TokenProcessor, NonConstPointerGetterAsArgument)
@@ -1400,7 +1400,7 @@ TEST_F(TokenProcessor, NonConstPointerArgumentAsExpression)
infos[1]; infos[1];
ASSERT_THAT(infos[3], ASSERT_THAT(infos[3],
HasOnlyType(HighlightingType::LocalVariable)); HasTwoTypes(HighlightingType::LocalVariable, HighlightingType::OutputArgument));
} }
TEST_F(TokenProcessor, NonConstPointerArgumentAsInstanceWithMember) TEST_F(TokenProcessor, NonConstPointerArgumentAsInstanceWithMember)