================
@@ -0,0 +1,180 @@
+// RUN: %check_clang_tidy %s misc-const-correctness %t -- \
+// RUN:   -config="{CheckOptions: {\
+// RUN:     misc-const-correctness.AllowedTypes: 
'[Pp]ointer$;[Pp]tr$;[Rr]ef(erence)?$;qualified::Type;::fully::QualifiedType;ConstTemplate',
 \
+// RUN:     misc-const-correctness.TransformPointersAsValues: true, \
+// RUN:     misc-const-correctness.TransformReferences: true, \
+// RUN:     misc-const-correctness.WarnPointersAsValues: true } \
+// RUN:   }" -- -fno-delayed-template-parsing
+
+struct SmartPointer {
+};
+
+struct smart_pointer {
+};
+
+struct SmartPtr {
+};
+
+struct smart_ptr {
+};
+
+struct SmartReference {
+};
+
+struct smart_reference {
+};
+
+struct SmartRef {
+};
+
+struct smart_ref {
+};
+
+struct OtherType {
+};
+
+template <typename T> struct ConstTemplate {
+};
+
+namespace qualified {
+struct Type {
+};
+} // namespace qualified
+
+namespace fully {
+struct QualifiedType {
+};
+} // namespace fully
+
+void negativeSmartPointer() {
+  SmartPointer p1 = {};
+  SmartPointer* p2 = {};
+  SmartPointer& p3 = p1;
+}
+
+void negative_smart_pointer() {
+  smart_pointer p1 = {};
+  smart_pointer* p2 = {};
+  smart_pointer& p3 = p1;
+}
+
+void negativeSmartPtr() {
+  SmartPtr p1 = {};
+  SmartPtr* p2 = {};
+  SmartPtr& p3 = p1;
+}
+
+void negative_smart_ptr() {
+  smart_ptr p1 = {};
+  smart_ptr* p2 = {};
+  smart_ptr& p3 = p1;
+}
+
+void negativeSmartReference() {
+  SmartReference p1 = {};
+  SmartReference* p2 = {};
+  SmartReference& p3 = p1;
+}
+
+void negative_smart_reference() {
+  smart_reference p1 = {};
+  smart_reference* p2 = {};
+  smart_reference& p3 = p1;
+}
+
+void negativeSmartRef() {
+  SmartRef p1 = {};
+  SmartRef* p2 = {};
+  SmartRef& p3 = p1;
+}
+
+void negative_smart_ref() {
+  smart_ref p1 = {};
+  smart_ref* p2 = {};
+  smart_ref& p3 = p1;
+}
+
+void positiveOtherType() {
+  OtherType t = {};
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 't' of type 'OtherType' 
can be declared 'const'
+  // CHECK-FIXES: OtherType const t = {};
+}
+
+void negativeSomeComplex() {
+   ConstTemplate<int> t1 = {};
+   ConstTemplate<int>* t2 = {};
+   ConstTemplate<int>& t3 = t1;
+}
+
+void negativeQualified() {
+  qualified::Type t1 = {};
+  qualified::Type* t2 = {};
+  qualified::Type& t3 = t1;
+
+  using qualified::Type;
+  Type t4 = {};
+  Type* t5 = {};
+  Type& t6 = t4;
+}
+
+void negativeFullyQualified() {
+  fully::QualifiedType t1 = {};
+  fully::QualifiedType* t2 = {};
+  fully::QualifiedType& t3 = t1;
+
+  using fully::QualifiedType;
+  QualifiedType t4 = {};
+  QualifiedType* t5 = {};
+  QualifiedType& t6 = t4;
+}
----------------
vbvictor wrote:

> In other words, for a UsingType, do we disregard how that using type was 
> spelled, and only look at its underlying type?

Yes, I think we usually do that in clang-tidy. Here is [a piece of relevant 
code](https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/utils/Matchers.h#L108-L119),
 `Regex` here contains one of the entries of `AllowedTypes`. And the whole 
matcher for allowing type is 
`qualType(hasDeclaration(namedDecl(matchers::matchesAnyListedName(AllowedTypes))))`.

Here I purposly didn't use `hasCanonicalType` or `hasUnqualifiedDesugaredType` 
to allow users to specify aliased types directly in `AllowedType`, e.g. `using 
Mutex = std::mutex` with `AllowedTypes = Mutex`.



https://github.com/llvm/llvm-project/pull/122951
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to