1*46ae26e7SJonas Toth // RUN: %check_clang_tidy %s misc-const-correctness %t -- -- -std=c++17 -fno-delayed-template-parsing
2*46ae26e7SJonas Toth
3*46ae26e7SJonas Toth template <typename L, typename R>
4*46ae26e7SJonas Toth struct MyPair {
5*46ae26e7SJonas Toth L left;
6*46ae26e7SJonas Toth R right;
MyPairMyPair7*46ae26e7SJonas Toth MyPair(const L &ll, const R &rr) : left{ll}, right{rr} {}
8*46ae26e7SJonas Toth };
9*46ae26e7SJonas Toth
f()10*46ae26e7SJonas Toth void f() {
11*46ae26e7SJonas Toth // FIXME: Decomposition Decls need special treatment, because they require to use 'auto'
12*46ae26e7SJonas Toth // and the 'const' should only be added if all elements can be const.
13*46ae26e7SJonas Toth // The issue is similar to multiple declarations in one statement.
14*46ae26e7SJonas Toth // Simply bail for now.
15*46ae26e7SJonas Toth auto [np_local0, np_local1] = MyPair<int, int>(42, 42);
16*46ae26e7SJonas Toth np_local0++;
17*46ae26e7SJonas Toth np_local1++;
18*46ae26e7SJonas Toth // CHECK-FIXES-NOT: auto const [np_local0, np_local1]
19*46ae26e7SJonas Toth
20*46ae26e7SJonas Toth auto [np_local2, p_local0] = MyPair<double, double>(42., 42.);
21*46ae26e7SJonas Toth np_local2++;
22*46ae26e7SJonas Toth // CHECK-FIXES-NOT: auto const [np_local2, p_local0]
23*46ae26e7SJonas Toth
24*46ae26e7SJonas Toth auto [p_local1, np_local3] = MyPair<double, double>(42., 42.);
25*46ae26e7SJonas Toth np_local3++;
26*46ae26e7SJonas Toth // CHECK-FIXES-NOT: auto const [p_local1, np_local3]
27*46ae26e7SJonas Toth
28*46ae26e7SJonas Toth auto [p_local2, p_local3] = MyPair<double, double>(42., 42.);
29*46ae26e7SJonas Toth // CHECK-FIXES-NOT: auto const [p_local2, p_local3]
30*46ae26e7SJonas Toth }
31*46ae26e7SJonas Toth
g()32*46ae26e7SJonas Toth void g() {
33*46ae26e7SJonas Toth int p_local0 = 42;
34*46ae26e7SJonas Toth // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'int' can be declared 'const'
35*46ae26e7SJonas Toth // CHECK-FIXES: int const p_local0 = 42;
36*46ae26e7SJonas Toth }
37*46ae26e7SJonas Toth
38*46ae26e7SJonas Toth template <typename SomeValue>
39*46ae26e7SJonas Toth struct DoGooder {
DoGooderDoGooder40*46ae26e7SJonas Toth DoGooder(void *accessor, SomeValue value) {
41*46ae26e7SJonas Toth }
42*46ae26e7SJonas Toth };
43*46ae26e7SJonas Toth struct Bingus {
44*46ae26e7SJonas Toth static constexpr auto someRandomConstant = 99;
45*46ae26e7SJonas Toth };
46*46ae26e7SJonas Toth template <typename Foo>
47*46ae26e7SJonas Toth struct HardWorker {
HardWorkerHardWorker48*46ae26e7SJonas Toth HardWorker() {
49*46ae26e7SJonas Toth const DoGooder<int> anInstanceOf(nullptr, Foo::someRandomConstant);
50*46ae26e7SJonas Toth }
51*46ae26e7SJonas Toth };
52*46ae26e7SJonas Toth struct TheContainer {
53*46ae26e7SJonas Toth HardWorker<Bingus> m_theOtherInstance;
54*46ae26e7SJonas Toth // CHECK-FIXES-NOT: HardWorker<Bingus> const m_theOtherInstance
55*46ae26e7SJonas Toth };
56