return llvm::any_of(
Result.Context->getParents(ExprResult),
[&Result](const DynTypedNode &Parent) {
- return isUsedToInitializeAConstant(Result, Parent) ||
- // Ignore this instance, because this match reports the location
- // where the template is defined, not where it is instantiated.
- Parent.get<SubstNonTypeTemplateParmExpr>();
+ if (isUsedToInitializeAConstant(Result, Parent))
+ return true;
+
+ // Ignore this instance, because this match reports the location
+ // where the template is defined, not where it is instantiated.
+ if (Parent.get<SubstNonTypeTemplateParmExpr>())
+ return true;
+
+ // Don't warn on string user defined literals:
+ // std::string s = "Hello World"s;
+ if (const auto *UDL = Parent.get<UserDefinedLiteral>())
+ if (UDL->getLiteralOperatorKind() == UserDefinedLiteral::LOK_String)
+ return true;
+
+ return false;
});
}
--- /dev/null
+// RUN: %check_clang_tidy -std=c++14-or-later %s readability-magic-numbers %t --
+
+namespace std {
+ class string {};
+ using size_t = decltype(sizeof(int));
+ string operator ""s(const char *, std::size_t);
+ int operator "" s(unsigned long long);
+}
+
+void UserDefinedLiteral() {
+ using std::operator ""s;
+ "Hello World"s;
+ const int i = 3600s;
+ int j = 3600s;
+ // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 3600s is a magic number; consider replacing it with a named constant [readability-magic-numbers]
+}