diff --git a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp --- a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp @@ -103,7 +103,7 @@ } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) { const QualType T = VD->getType(); if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) || - T->isArrayType()) + T->isArrayType() || T->isRecordType()) markCanNotBeConst(VD->getInit(), true); else if (T->isLValueReferenceType() && !T->getPointeeType().isConstQualified()) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -227,6 +227,10 @@ do-while loops into account for the `AllowIntegerConditions` and `AllowPointerConditions` options. +- Improved :doc:`readability-non-const-parameter + ` check to ignore + false-positives in initializer list of record. + - Improved :doc:`readability-static-accessed-through-instance ` check to identify calls to static member functions with out-of-class inline definitions. diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.cpp @@ -222,6 +222,18 @@ void recordpointer(struct XY *xy) { *(xy->x) = 0; } +void recordInitList(int *x) { + XY xy = {x, nullptr}; +} + +struct XYConst { + int const *x; +}; +// CHECK-MESSAGES: :[[@LINE+1]]:30: warning: pointer parameter 'x' can be pointer to const +void recordInitListDiag(int *x) { + // CHECK-FIXES: {{^}}void recordInitListDiag(const int *x) {{{$}} + XYConst xy = {x}; +} class C { public: