
Some user-defined literals operate on implementation-defined types, like "unsigned long long" and "long double", which are not well supported by this check. Currently, the check gives warnings when using UDLs, without giving possiblity to the user to whitelist common UDLs. A good compromise until a proper fix is found (if any) is to allow the user to disable warnings on UDLs. Partially fixes #61656 Differential Revision: https://reviews.llvm.org/D146913
29 lines
1.4 KiB
C++
29 lines
1.4 KiB
C++
// RUN: %check_clang_tidy -check-suffixes=UDL-ALLOWED -std=c++14-or-later %s readability-magic-numbers %t \
|
|
// RUN: -config='{CheckOptions: \
|
|
// RUN: [{key: readability-magic-numbers.IgnoreUserDefinedLiterals, value: false}]}' \
|
|
// RUN: --
|
|
// RUN: %check_clang_tidy -check-suffixes=UDL-IGNORED -std=c++14-or-later %s readability-magic-numbers %t \
|
|
// RUN: -config='{CheckOptions: \
|
|
// RUN: [{key: readability-magic-numbers.IgnoreUserDefinedLiterals, value: true}]}' \
|
|
// RUN: --
|
|
|
|
namespace std {
|
|
class string {};
|
|
using size_t = decltype(sizeof(int));
|
|
string operator ""s(const char *, std::size_t);
|
|
int operator "" s(unsigned long long);
|
|
float operator "" s(long double);
|
|
}
|
|
|
|
void UserDefinedLiteral() {
|
|
using std::operator ""s;
|
|
"Hello World"s;
|
|
const int i = 3600s;
|
|
int j = 3600s;
|
|
// CHECK-MESSAGES-UDL-ALLOWED: :[[@LINE-1]]:11: warning: 3600s is a magic number; consider replacing it with a named constant [readability-magic-numbers]
|
|
// CHECK-MESSAGES-UDL-IGNORED-NOT: :[[@LINE-2]]:11: warning: 3600s is a magic number; consider replacing it with a named constant [readability-magic-numbers]
|
|
float k = 3600.0s;
|
|
// CHECK-MESSAGES-UDL-ALLOWED: :[[@LINE-1]]:13: warning: 3600.0s is a magic number; consider replacing it with a named constant [readability-magic-numbers]
|
|
// CHECK-MESSAGES-UDL-IGNORED-NOT: :[[@LINE-1]]:13: warning: 3600.0s is a magic number; consider replacing it with a named constant [readability-magic-numbers]
|
|
}
|