diff --git a/clang/lib/Analysis/UninitializedValues.cpp b/clang/lib/Analysis/UninitializedValues.cpp --- a/clang/lib/Analysis/UninitializedValues.cpp +++ b/clang/lib/Analysis/UninitializedValues.cpp @@ -405,6 +405,15 @@ return QT->isAnyPointerType() && QT->getPointeeType().isConstQualified(); } +static bool hasTrivialBody(CallExpr *CE) { + if (FunctionDecl *fd = CE->getDirectCallee()) { + if (FunctionTemplateDecl *ftd = fd->getPrimaryTemplate()) + return ftd->getTemplatedDecl()->hasTrivialBody(); + return fd->hasTrivialBody(); + } + return false; +} + void ClassifyRefs::VisitCallExpr(CallExpr *CE) { // Classify arguments to std::move as used. if (CE->isCallToStdMove()) { @@ -423,7 +432,8 @@ I != E; ++I) { if ((*I)->isGLValue()) { if ((*I)->getType().isConstQualified()) - classify((*I), ConstRefUse); + if (!hasTrivialBody(CE)) + classify((*I), ConstRefUse); } else if (isPointerToConst((*I)->getType())) { const Expr *Ex = stripCasts(DC->getParentASTContext(), *I); const auto *UO = dyn_cast(Ex); diff --git a/clang/test/SemaCXX/warn-uninitialized-const-reference.cpp b/clang/test/SemaCXX/warn-uninitialized-const-reference.cpp --- a/clang/test/SemaCXX/warn-uninitialized-const-reference.cpp +++ b/clang/test/SemaCXX/warn-uninitialized-const-reference.cpp @@ -9,6 +9,9 @@ bool operator!=(const A &); }; +template +inline void ignore_template(T const &) {} +void ignore(const int &i) {} A const_ref_use_A(const A &a); int const_ref_use(const int &i); A const_use_A(const A a); @@ -33,4 +36,8 @@ if (a < 42) m = 1; const_ref_use(m); + + int l; + ignore_template(l); + ignore(l); }