<< Parameter->getFunctionScopeIndex();
} else {
diag(Parameter->getLocation(),
- "non-const reference parameter '%0', make it const or use a pointer")
- << Parameter->getName();
+ "non-const reference parameter %0, make it const or use a pointer")
+ << Parameter;
}
}
}
diag(FD->getLocation(),
- "function '%0' defined in a header file; "
+ "function %0 defined in a header file; "
"function definitions in header files can lead to ODR violations")
- << FD->getNameInfo().getName().getAsString()
- << FixItHint::CreateInsertion(FD->getSourceRange().getBegin(),
- "inline ");
+ << FD << FixItHint::CreateInsertion(FD->getSourceRange().getBegin(),
+ "inline ");
} else if (const auto *VD = dyn_cast<VarDecl>(ND)) {
// Static data members of a class template are allowed.
if (VD->getDeclContext()->isDependentContext() && VD->isStaticDataMember())
return;
diag(VD->getLocation(),
- "variable '%0' defined in a header file; "
+ "variable %0 defined in a header file; "
"variable definitions in header files can lead to ODR violations")
- << VD->getName();
+ << VD;
}
}
if (!CurDecl->hasDefinition() &&
!haveSameNamespaceOrTranslationUnit(CurDecl, Decl)) {
diag(CurDecl->getLocation(),
- "declaration '%0' is never referenced, but a declaration with "
+ "declaration %0 is never referenced, but a declaration with "
"the same name found in another namespace '%1'")
- << CurDecl->getName() << getNameOfNamespace(Decl);
- diag(Decl->getLocation(), "a declaration of '%0' is found here",
+ << CurDecl << getNameOfNamespace(Decl);
+ diag(Decl->getLocation(), "a declaration of %0 is found here",
DiagnosticIDs::Note)
- << Decl->getName();
+ << Decl;
break; // FIXME: We only generate one warning for each declaration.
}
}
const auto &Definitions = DeclNameToDefinitions[DeclName];
for (const auto *Def : Definitions) {
diag(CurDecl->getLocation(),
- "no definition found for '%0', but a definition with "
- "the same name '%1' found in another namespace '%2'")
- << CurDecl->getName() << Def->getName() << getNameOfNamespace(Def);
- diag(Def->getLocation(), "a definition of '%0' is found here",
+ "no definition found for %0, but a definition with "
+ "the same name %1 found in another namespace '%2'")
+ << CurDecl << Def << getNameOfNamespace(Def);
+ diag(Def->getLocation(), "a definition of %0 is found here",
DiagnosticIDs::Note)
- << Def->getName();
+ << Def;
}
}
}
if (hasSideEffects(ResultArgToks) &&
countArgumentExpansions(MI, Arg) >= 2) {
Check.diag(ResultArgToks->getLocation(),
- "side effects in the %ordinal0 macro argument '%1' are "
+ "side effects in the %ordinal0 macro argument %1 are "
"repeated in macro expansion")
- << (ArgNo + 1) << Arg->getName();
+ << (ArgNo + 1) << Arg;
Check.diag(MI->getDefinitionLoc(), "macro %0 defined here",
DiagnosticIDs::Note)
<< MacroNameTok.getIdentifierInfo();
const auto *E = Result.Nodes.getNodeAs<Expr>("expr");
if (D && BD)
- diag(D->getLocation(), "'%0' declared as type '%1', which is unsafe to copy"
- "; did you mean '%1 *'?")
- << D->getName() << BD->getName();
+ diag(D->getLocation(), "%0 declared as type '%1', which is unsafe to copy"
+ "; did you mean '%1 *'?")
+ << D << BD->getName();
else if (E)
diag(E->getExprLoc(),
- "expression has opaque data structure type '%0'; type should only be "
+ "expression has opaque data structure type %0; type should only be "
"used as a pointer and not dereferenced")
- << BD->getName();
+ << BD;
}
} // namespace tidy
for (const auto &FoundDecl : FoundDecls) {
if (!FoundDecl.second.isValid())
continue;
- diag(FoundDecl.first->getLocation(), "namespace alias decl '%0' is unused")
- << FoundDecl.first->getName()
- << FixItHint::CreateRemoval(FoundDecl.second);
+ diag(FoundDecl.first->getLocation(), "namespace alias decl %0 is unused")
+ << FoundDecl.first << FixItHint::CreateRemoval(FoundDecl.second);
}
}
const MatchFinder::MatchResult &Result, const FunctionDecl *Function,
unsigned ParamIndex) {
const auto *Param = Function->getParamDecl(ParamIndex);
- auto MyDiag = diag(Param->getLocation(), "parameter '%0' is unused")
- << Param->getName();
+ auto MyDiag = diag(Param->getLocation(), "parameter %0 is unused") << Param;
auto DeclRefExpr =
declRefExpr(to(equalsNode(Function)),
diag(Literal->getLocStart(), "%0 called with a string literal consisting of "
"a single character; consider using the more "
"effective overload accepting a character")
- << FindFunc->getName()
- << FixItHint::CreateReplacement(
- CharSourceRange::getTokenRange(Literal->getLocStart(),
- Literal->getLocEnd()),
- *Replacement);
+ << FindFunc << FixItHint::CreateReplacement(
+ CharSourceRange::getTokenRange(Literal->getLocStart(),
+ Literal->getLocEnd()),
+ *Replacement);
}
} // namespace performance
QualType ConstType = OperatorCall->getType().withConst();
QualType ConstRefType = Context->getLValueReferenceType(ConstType);
const char Message[] =
- "the type of the loop variable '%0' is different from the one returned "
+ "the type of the loop variable %0 is different from the one returned "
"by the iterator and generates an implicit cast; you can either "
- "change the type to the correct one ('%1' but 'const auto&' is always a "
+ "change the type to the correct one (%1 but 'const auto&' is always a "
"valid option) or remove the reference to make it explicit that you are "
"creating a new value";
- PrintingPolicy Policy(Context->getLangOpts());
- Policy.SuppressTagKeyword = true;
-
- diag(VD->getLocStart(), Message) << VD->getName()
- << ConstRefType.getAsString(Policy);
+ diag(VD->getLocStart(), Message) << VD << ConstRefType;
}
} // namespace performance
if (FI.Lines > LineThreshold || FI.Statements > StatementThreshold ||
FI.Branches > BranchThreshold) {
diag(P.first->getLocation(),
- "function '%0' exceeds recommended size/complexity thresholds")
- << P.first->getNameAsString();
+ "function %0 exceeds recommended size/complexity thresholds")
+ << P.first;
}
if (FI.Lines > LineThreshold) {
template <>
int CA::f3() {
-// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: function 'f3' defined in a header file;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: function 'f3<int>' defined in a header file;
int a = 1;
return a;
}
}
template <>
-// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: function 'f3' defined in a header file;
+// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: function 'f3<int>' defined in a header file;
int f3() {
int a = 1;
return a;
std::string Str;
Str.find("a");
- // CHECK-MESSAGES: [[@LINE-1]]:12: warning: find called with a string literal consisting of a single character; consider using the more effective overload accepting a character [performance-faster-string-find]
+ // CHECK-MESSAGES: [[@LINE-1]]:12: warning: 'find' called with a string literal consisting of a single character; consider using the more effective overload accepting a character [performance-faster-string-find]
// CHECK-FIXES: Str.find('a');
// Works with the pos argument.
Str.find("a", 1);
- // CHECK-MESSAGES: [[@LINE-1]]:12: warning: find called with a string literal
+ // CHECK-MESSAGES: [[@LINE-1]]:12: warning: 'find' called with a string literal
// CHECK-FIXES: Str.find('a', 1);
// Doens't work with strings smaller or larger than 1 char.
// Other methods that can also be replaced
Str.rfind("a");
- // CHECK-MESSAGES: [[@LINE-1]]:13: warning: rfind called with a string literal
+ // CHECK-MESSAGES: [[@LINE-1]]:13: warning: 'rfind' called with a string literal
// CHECK-FIXES: Str.rfind('a');
Str.find_first_of("a");
- // CHECK-MESSAGES: [[@LINE-1]]:21: warning: find_first_of called with a string
+ // CHECK-MESSAGES: [[@LINE-1]]:21: warning: 'find_first_of' called with a string
// CHECK-FIXES: Str.find_first_of('a');
Str.find_first_not_of("a");
- // CHECK-MESSAGES: [[@LINE-1]]:25: warning: find_first_not_of called with a
+ // CHECK-MESSAGES: [[@LINE-1]]:25: warning: 'find_first_not_of' called with a
// CHECK-FIXES: Str.find_first_not_of('a');
Str.find_last_of("a");
- // CHECK-MESSAGES: [[@LINE-1]]:20: warning: find_last_of called with a string
+ // CHECK-MESSAGES: [[@LINE-1]]:20: warning: 'find_last_of' called with a string
// CHECK-FIXES: Str.find_last_of('a');
Str.find_last_not_of("a");
- // CHECK-MESSAGES: [[@LINE-1]]:24: warning: find_last_not_of called with a
+ // CHECK-MESSAGES: [[@LINE-1]]:24: warning: 'find_last_not_of' called with a
// CHECK-FIXES: Str.find_last_not_of('a');
// std::wstring should work.
std::wstring WStr;
WStr.find(L"n");
- // CHECK-MESSAGES: [[@LINE-1]]:13: warning: find called with a string literal
+ // CHECK-MESSAGES: [[@LINE-1]]:13: warning: 'find' called with a string literal
// CHECK-FIXES: Str.find(L'n');
// Even with unicode that fits in one wide char.
WStr.find(L"\x3A9");
- // CHECK-MESSAGES: [[@LINE-1]]:13: warning: find called with a string literal
+ // CHECK-MESSAGES: [[@LINE-1]]:13: warning: 'find' called with a string literal
// CHECK-FIXES: Str.find(L'\x3A9');
// Also with other types, but only if it was specified in the options.
llvm::StringRef sr;
sr.find("x");
- // CHECK-MESSAGES: [[@LINE-1]]:11: warning: find called with a string literal
+ // CHECK-MESSAGES: [[@LINE-1]]:11: warning: 'find' called with a string literal
// CHECK-FIXES: sr.find('x');
NotStringRef nsr;
nsr.find("x");
template <typename T>
int FindTemplateNotDependant(T pos) {
return std::string().find("A", pos);
- // CHECK-MESSAGES: [[@LINE-1]]:29: warning: find called with a string literal
+ // CHECK-MESSAGES: [[@LINE-1]]:29: warning: 'find' called with a string literal
// CHECK-FIXES: return std::string().find('A', pos);
}
int Macros() {
return STR_MACRO(std::string()) + POS_MACRO(1);
- // CHECK-MESSAGES: [[@LINE-1]]:10: warning: find called with a string literal
- // CHECK-MESSAGES: [[@LINE-2]]:37: warning: find called with a string literal
+ // CHECK-MESSAGES: [[@LINE-1]]:10: warning: 'find' called with a string literal
+ // CHECK-MESSAGES: [[@LINE-2]]:37: warning: 'find' called with a string literal
}