From 9b5d6546b8282f237214115285fc864b87f2d857 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Thu, 20 Jul 2017 17:06:36 +0200 Subject: [PATCH] Clang: Remove pointer arguments from output argument Non constant pointers are used many times as non output arguments, so you get misleading information. Task-number: QTCREATORBUG-18591 Change-Id: Ic5f987db44ad63a0b1a38fd59cd807db5f2acc8f Reviewed-by: Nikolai Kosjar --- src/tools/clangbackend/ipcsource/clangtype.cpp | 2 +- tests/unit/unittest/data/highlightingmarks.cpp | 6 +++--- tests/unit/unittest/highlightingmarks-test.cpp | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/tools/clangbackend/ipcsource/clangtype.cpp b/src/tools/clangbackend/ipcsource/clangtype.cpp index dd0e192f7a3..8fc09d8c4af 100644 --- a/src/tools/clangbackend/ipcsource/clangtype.cpp +++ b/src/tools/clangbackend/ipcsource/clangtype.cpp @@ -76,7 +76,7 @@ bool Type::isReferencingConstant() const bool Type::isOutputArgument() const { - return (isPointer() || isLValueReference()) && !pointeeType().isConstant(); + return isLValueReference() && !pointeeType().isConstant(); } bool Type::isBuiltinType() const diff --git a/tests/unit/unittest/data/highlightingmarks.cpp b/tests/unit/unittest/data/highlightingmarks.cpp index a954df3e973..7c78ddf1965 100644 --- a/tests/unit/unittest/data/highlightingmarks.cpp +++ b/tests/unit/unittest/data/highlightingmarks.cpp @@ -482,12 +482,12 @@ void f25() NonConstPointerArgument(x); } -void ConstPointerArgument(const int *argument); - +void PointerToConstArgument(const int *argument); +void ConstPointerArgument(int *const argument); void f26() { int *x; - + PointerToConstArgument(x); ConstPointerArgument(x); } diff --git a/tests/unit/unittest/highlightingmarks-test.cpp b/tests/unit/unittest/highlightingmarks-test.cpp index e72d25c9711..c22c3e2df88 100644 --- a/tests/unit/unittest/highlightingmarks-test.cpp +++ b/tests/unit/unittest/highlightingmarks-test.cpp @@ -998,7 +998,17 @@ TEST_F(HighlightingMarks, NonConstPointerArgument) infos[1]; ASSERT_THAT(infos[2], - HasTwoTypes(HighlightingType::LocalVariable, HighlightingType::OutputArgument)); + HasOnlyType(HighlightingType::LocalVariable)); +} + +TEST_F(HighlightingMarks, PointerToConstArgument) +{ + const auto infos = translationUnit.highlightingMarksInRange(sourceRange(490, 31)); + + infos[1]; + + ASSERT_THAT(infos[2], + HasOnlyType(HighlightingType::LocalVariable)); } TEST_F(HighlightingMarks, ConstPointerArgument) @@ -1048,7 +1058,7 @@ TEST_F(HighlightingMarks, NonConstPointerArgumentAsExpression) infos[1]; ASSERT_THAT(infos[3], - HasTwoTypes(HighlightingType::LocalVariable, HighlightingType::OutputArgument)); + HasOnlyType(HighlightingType::LocalVariable)); } TEST_F(HighlightingMarks, NonConstPointerArgumentAsInstanceWithMember)