================
@@ -0,0 +1,157 @@
+// RUN: %check_clang_tidy -std=c++11-or-later %s readability-redundant-const %t
+
+struct Foo {};
+
+// Simple allowed usages, nothing to warn
+constexpr int n1 = 10;
+const int n2 = 20;
+constexpr Foo n3 = {};
+
+constexpr const int p1 = 10;
+// CHECK-MESSAGES: [[@LINE-1]]:11: warning: redundant use of `const`; 
`constexpr` already implies `const`.
+// CHECK-FIXES: constexpr int p1 = 10;
+
+const constexpr int p2 = 20;
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: redundant use of `const`; 
`constexpr` already implies `const`.
+// CHECK-FIXES: constexpr int p2 = 20;
+
+static const constexpr int p3 = 20;
+// CHECK-MESSAGES: [[@LINE-1]]:8: warning: redundant use of `const`; 
`constexpr` already implies `const`.
+// CHECK-FIXES: static constexpr int p3 = 20;
+
+constexpr const Foo p4 = {};
+// CHECK-MESSAGES: [[@LINE-1]]:11: warning: redundant use of `const`; 
`constexpr` already implies `const`.
+// CHECK-FIXES: constexpr Foo p4 = {};
+
+// Since constexpr makes only the pointer const, this usage is not redundant.
+constexpr const char* n4 = "hello";
+
+constexpr const char* const n5 = "hello";
+// CHECK-MESSAGES: [[@LINE-1]]:23: warning: redundant use of `const`; 
`constexpr` already implies `const`.
+// CHECK-FIXES: constexpr const char* n5 = "hello";
+
+template<typename T>
+const constexpr T n6 = {};
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: redundant use of `const`; 
`constexpr` already implies `const`.
+// CHECK-FIXES: constexpr T n6 = {};
+
+constexpr const int* n7 = n6<int*>;
+
+const constexpr double p5 = n6<double>;
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: redundant use of `const`; 
`constexpr` already implies `const`.
+// CHECK-FIXES: constexpr double p5 = n6<double>;
+
+constexpr const int* const p6 = n6<int*>;
+// CHECK-MESSAGES: [[@LINE-1]]:22: warning: redundant use of `const`; 
`constexpr` already implies `const`.
+// CHECK-FIXES: constexpr const int* p6 = n6<int*>;
+
+void f() {
+  constexpr Foo n1 = {};
+  const Foo n2 = {};
+
+  const constexpr Foo p1 = {};
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: redundant use of `const`; 
`constexpr` already implies `const`.
+  // CHECK-FIXES: constexpr Foo p1 = {};
+
+  static const constexpr Foo p2 = {};
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: redundant use of `const`; 
`constexpr` already implies `const`.
+  // CHECK-FIXES: static constexpr Foo p2 = {};
+}
+
+struct Config {
+    static const constexpr bool p = false;
+    // CHECK-MESSAGES: [[@LINE-1]]:12: warning: redundant use of `const`; 
`constexpr` already implies `const`.
+    // CHECK-FIXES: static constexpr bool p = false;
+};
+
+template <typename T>
+class Templated {
+    static const constexpr int size = 10;
+    // CHECK-MESSAGES: [[@LINE-1]]:12: warning: redundant use of `const`; 
`constexpr` already implies `const`.
+    // CHECK-FIXES: static constexpr int size = 10;
+    int data[size];
+};
+
+constexpr Templated<int> b{};
+
+template <int N>
+struct Templated2 {
+    static const constexpr int size = N;
+    // CHECK-MESSAGES: [[@LINE-1]]:12: warning: redundant use of `const`; 
`constexpr` already implies `const`.
+    // CHECK-FIXES: static constexpr int size = N;
+    int data[size];
+};
+
+static constexpr int n8[] = {0, 1, 4, 9, 16};
+
+constexpr const int p7[] = {0, 1, 4, 9, 16};
+// CHECK-MESSAGES: [[@LINE-1]]:11: warning: redundant use of `const`; 
`constexpr` already implies `const`.
+// CHECK-FIXES: constexpr int p7[] = {0, 1, 4, 9, 16};
+
+constexpr int square(int n) { return n * n; }
+
+const constexpr int p8 = square(10);
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: redundant use of `const`; 
`constexpr` already implies `const`.
+// CHECK-FIXES: constexpr int p8 = square(10);
+
+constexpr int n9 = square(5);
+
+constexpr Foo** n10 = nullptr;
----------------
berkaysahiin wrote:

`Foo&*` is this valid ? 

https://godbolt.org/z/1fovcnf3W

https://github.com/llvm/llvm-project/pull/189733
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to