// RUN: %check_clang_tidy %s misc-const-correctness %t -- \ // RUN: -config="{CheckOptions: {\ // RUN: misc-const-correctness.TransformValues: true, \ // RUN: misc-const-correctness.TransformReferences: true, \ // RUN: misc-const-correctness.WarnPointersAsValues: false, \ // RUN: misc-const-correctness.TransformPointersAsValues: false} \ // RUN: }" -- -fno-delayed-template-parsing template void type_dependent_variables() { T value = 42; auto &ref = value; T &templateRef = value; int value_int = 42; // CHECK-MESSAGES:[[@LINE-1]]:3: warning: variable 'value_int' of type 'int' can be declared 'const' // CHECK-FIXES: int const value_int } void instantiate_template_cases() { type_dependent_variables(); type_dependent_variables(); } namespace gh57297{ // The expression to check may not be the dependent operand in a dependent // operator. // Explicitly not declaring a (templated) stream operator // so the `<<` is a `binaryOperator` with a dependent type. struct Stream { }; template void f() { T t; Stream x; x << t; } } // namespace gh57297 namespace gh70323{ // A fold expression may contain the checked variable as it's initializer. // We don't know if the operator modifies that variable because the // operator is type dependent due to the parameter pack. struct Stream {}; template void concatenate1(Args... args) { Stream stream; (stream << ... << args); } template void concatenate2(Args... args) { Stream stream; (args << ... << stream); } template void concatenate3(Args... args) { Stream stream; (..., (stream << args)); } } // namespace gh70323 namespace gh60895 { template void f1(T &&a); template void f2(T &&a); template void f1(T &&a) { f2(a); } template void f2(T &&a) { f1(a); } void f() { int x = 0; // CHECK-MESSAGES:[[@LINE-1]]:3: warning: variable 'x' of type 'int' can be declared 'const' // CHECK-FIXES: int const x = 0; f1(x); } } // namespace gh60895