Files
TheRock/compiler/amd-llvm/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-parentheses.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

211 lines
6.7 KiB
C++

// RUN: %check_clang_tidy %s readability-redundant-parentheses %t
void parenExpr() {
1 + 1;
(1 + 1);
((1 + 1));
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: (1 + 1);
(((1 + 1)));
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-MESSAGES: :[[@LINE-2]]:4: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: (1 + 1);
((((1 + 1))));
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-MESSAGES: :[[@LINE-2]]:4: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-MESSAGES: :[[@LINE-3]]:5: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: (1 + 1);
}
#define EXP (1 + 1)
#define PAREN(e) (e)
void parenExprWithMacro() {
EXP; // 1
(EXP); // 2
((EXP)); // 3
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: (EXP); // 3
PAREN((1));
}
void constant() {
(1);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: 1;
(1.0);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: 1.0;
(true);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: true;
(',');
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: ',';
("v4");
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: "v4";
(nullptr);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: nullptr;
}
void declRefExpr(int a) {
(a);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: a;
}
void exceptions() {
sizeof(1);
alignof(2);
alignof((3));
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: alignof(3);
}
namespace std {
template<class T> T max(T, T);
template<class T> T min(T, T);
} // namespace std
void ignoreStdMaxMin() {
(std::max)(1,2);
(std::min)(1,2);
}
struct Foo
{
bool x;
struct Y {
bool z;
} y;
void foo()
{
if ((x)) {
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: if (x) {
}
if((this->x)) {
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: if(this->x) {
}
}
bool bar() {
return true;
}
Y fooBar() {
Y y{};
return y;
}
};
void memberExpr() {
Foo foo{};
if ((foo.x)) {
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: if (foo.x) {
}
if ((foo.y.z)) {
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: if (foo.y.z) {
}
if ((foo.bar())) {
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: if (foo.bar()) {
}
if ((foo.fooBar().z)) {
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: if (foo.fooBar().z) {
}
}
enum class FoldLevel {
None = 0x0,
HeaderFlag = 0x2000,
};
int FoldLevelToInt(FoldLevel l) {
return static_cast<int>(l);
}
constexpr FoldLevel operator&(FoldLevel lhs, FoldLevel rhs) {
return static_cast<FoldLevel>(static_cast<int>(lhs) & static_cast<int>(rhs));
}
constexpr FoldLevel operator*(FoldLevel lhs, FoldLevel rhs) {
return static_cast<FoldLevel>(static_cast<int>(lhs) * static_cast<int>(rhs));
}
constexpr FoldLevel operator!(FoldLevel operand) {
return static_cast<FoldLevel>(!static_cast<int>(operand));
}
constexpr FoldLevel operator+(FoldLevel lhs, FoldLevel rhs) {
return lhs;
}
constexpr bool UseOperatorAmpersand1(FoldLevel level) {
return (level & FoldLevel::HeaderFlag) != FoldLevel::None;
}
constexpr bool UseOperatorAmpersand2(FoldLevel level) {
const FoldLevel l = level & FoldLevel::HeaderFlag;
return (l != FoldLevel::None);
}
constexpr bool UseOperatorAmpersand3(FoldLevel level) {
return ((level & FoldLevel::HeaderFlag) != FoldLevel::None);
}
constexpr bool UseOperatorAmpersand4(FoldLevel level) {
return FoldLevel::None != (level & FoldLevel::HeaderFlag);
}
constexpr bool UseOperatorAmpersand5(FoldLevel level) {
FoldLevel hf = FoldLevel::HeaderFlag;
// currently this check doesn't take into account order of operations, so the
// parentheses around `left & rhs` is needed
return ((level & hf) * hf) != FoldLevel::None;
}
constexpr bool UseOperatorAmpersand6(FoldLevel level) {
FoldLevel hf = FoldLevel::HeaderFlag;
return (!(level & hf) * hf) != FoldLevel::None;
}
constexpr FoldLevel UseOperatorAmpersand7(FoldLevel level) {
FoldLevel hf = FoldLevel::HeaderFlag;
return !(level & hf) * hf;
}
constexpr FoldLevel UseOperatorAmpersand8(FoldLevel level) {
FoldLevel hf = FoldLevel::HeaderFlag;
return hf * !(level & hf);
}
constexpr FoldLevel UseOperatorAmpersand9(FoldLevel level) {
FoldLevel hf = FoldLevel::HeaderFlag;
return !(level & hf);
}
constexpr bool UseOperatorPlus1(FoldLevel level) {
return (FoldLevelToInt(level + FoldLevel::None)) != 1;
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: return FoldLevelToInt(level + FoldLevel::None) != 1;
}
constexpr bool UseOperatorPlus2(FoldLevel level) {
return (FoldLevelToInt(!(level + FoldLevel::None))) != 1;
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: return FoldLevelToInt(!(level + FoldLevel::None)) != 1;
}
const int bracket_int_plus_num = (4) + 5;
// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: redundant parentheses around expression [readability-redundant-parentheses]
// CHECK-FIXES: const int bracket_int_plus_num = 4 + 5;