76 lines · cpp
1// RUN: %check_clang_tidy %s misc-const-correctness %t -- \2// RUN: -config="{CheckOptions: {\3// RUN: misc-const-correctness.TransformValues: true, \4// RUN: misc-const-correctness.TransformReferences: true, \5// RUN: misc-const-correctness.WarnPointersAsValues: false, \6// RUN: misc-const-correctness.TransformPointersAsValues: false} \7// RUN: }" -- -fno-delayed-template-parsing8 9template <typename T>10void type_dependent_variables() {11 T value = 42;12 auto &ref = value;13 T &templateRef = value;14 15 int value_int = 42;16 // CHECK-MESSAGES:[[@LINE-1]]:3: warning: variable 'value_int' of type 'int' can be declared 'const'17 // CHECK-FIXES: int const value_int = 42;18}19void instantiate_template_cases() {20 type_dependent_variables<int>();21 type_dependent_variables<float>();22}23 24namespace gh57297{25// The expression to check may not be the dependent operand in a dependent26// operator.27 28// Explicitly not declaring a (templated) stream operator29// so the `<<` is a `binaryOperator` with a dependent type.30struct Stream { };31template <typename T> void f() { T t; Stream x; x << t; }32} // namespace gh5729733 34namespace gh70323{35// A fold expression may contain the checked variable as it's initializer.36// We don't know if the operator modifies that variable because the37// operator is type dependent due to the parameter pack.38 39struct Stream {};40template <typename... Args>41void concatenate1(Args... args)42{43 Stream stream;44 (stream << ... << args);45}46 47template <typename... Args>48void concatenate2(Args... args)49{50 Stream stream;51 (args << ... << stream);52}53 54template <typename... Args>55void concatenate3(Args... args)56{57 Stream stream;58 (..., (stream << args));59}60} // namespace gh7032361 62namespace gh60895 {63 64template <class T> void f1(T &&a);65template <class T> void f2(T &&a);66template <class T> void f1(T &&a) { f2<T>(a); }67template <class T> void f2(T &&a) { f1<T>(a); }68void f() {69 int x = 0;70 // CHECK-MESSAGES:[[@LINE-1]]:3: warning: variable 'x' of type 'int' can be declared 'const'71 // CHECK-FIXES: int const x = 0;72 f1(x);73}74 75} // namespace gh6089576