Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame] | 1 | // RUN: not %clang_cc1 -fsyntax-only -std=c++11 %s 2>&1 | FileCheck %s |
| 2 | |
| 3 | struct E { |
| 4 | int num; |
| 5 | const int Cnum = 0; |
| 6 | mutable int Mnum; |
| 7 | static int Snum; |
| 8 | const static int CSnum; |
| 9 | }; |
| 10 | |
| 11 | struct D { |
| 12 | E e; |
| 13 | const E Ce; |
| 14 | mutable E Me; |
| 15 | static E Se; |
| 16 | const static E CSe; |
| 17 | E &getE() const; |
| 18 | const E &getCE() const; |
| 19 | }; |
| 20 | |
| 21 | struct C { |
| 22 | D d; |
| 23 | const D Cd; |
| 24 | mutable D Md; |
| 25 | static D Sd; |
| 26 | const static D CSd; |
| 27 | D &getD() const; |
| 28 | const D &getCD() const; |
| 29 | }; |
| 30 | |
| 31 | struct B { |
| 32 | C c; |
| 33 | const C Cc; |
| 34 | mutable C Mc; |
| 35 | static C Sc; |
| 36 | const static C CSc; |
| 37 | C &getC() const; |
| 38 | static C &getSC(); |
| 39 | const C &getCC() const; |
| 40 | static const C &getSCC(); |
| 41 | }; |
| 42 | |
| 43 | struct A { |
| 44 | B b; |
| 45 | const B Cb; |
| 46 | mutable B Mb; |
| 47 | static B Sb; |
| 48 | const static B CSb; |
| 49 | B &getB() const; |
| 50 | static B &getSB(); |
| 51 | const B &getCB() const; |
| 52 | static const B &getSCB(); |
| 53 | }; |
| 54 | |
| 55 | A& getA(); |
| 56 | |
| 57 | // Valid assignment |
| 58 | void test1(A a, const A Ca) { |
| 59 | a.b.c.d.e.num = 5; |
| 60 | a.b.c.d.e.Mnum = 5; |
| 61 | Ca.b.c.d.e.Mnum = 5; |
| 62 | a.b.c.d.e.Snum = 5; |
| 63 | Ca.b.c.d.e.Snum = 5; |
| 64 | Ca.b.c.Md.e.num = 5; |
| 65 | Ca.Mb.Cc.d.e.Mnum = 5; |
| 66 | Ca.Mb.getC().d.e.num = 5; |
| 67 | Ca.getSB().c.d.e.num = 5; |
| 68 | a.getSCB().c.d.Me.num = 5; |
| 69 | Ca.Cb.Cc.Cd.Ce.Snum = 5; |
| 70 | // CHECK-NOT: error: |
| 71 | // CHECK-NOT: note: |
| 72 | } |
| 73 | |
| 74 | // One note |
| 75 | void test2(A a, const A Ca) { |
| 76 | Ca.b.c.d.e.num = 5; |
| 77 | // CHECK-NOT: error: |
| 78 | // CHECK: error:{{.*}} 'Ca' |
| 79 | // CHECK-NOT: note: |
| 80 | // CHECK: note:{{.*}} 'Ca' |
| 81 | // CHECK-NOT: note: |
| 82 | |
| 83 | a.Cb.c.d.e.num = 5; |
| 84 | // CHECK-NOT: error: |
| 85 | // CHECK: error:{{.*}} 'Cb' |
| 86 | // CHECK-NOT: note: |
| 87 | // CHECK: note:{{.*}} 'Cb' |
| 88 | // CHECK-NOT: note: |
| 89 | |
| 90 | a.b.c.Cd.e.num = 5; |
| 91 | // CHECK-NOT: error: |
| 92 | // CHECK: error:{{.*}} 'Cd' |
| 93 | // CHECK-NOT: note: |
| 94 | // CHECK: note:{{.*}} 'Cd' |
| 95 | // CHECK-NOT: note: |
| 96 | |
| 97 | a.b.c.d.e.CSnum = 5; |
| 98 | // CHECK-NOT: error: |
| 99 | // CHECK: error:{{.*}} 'CSnum' |
| 100 | // CHECK-NOT: note: |
| 101 | // CHECK: note:{{.*}} 'CSnum' |
| 102 | // CHECK-NOT: note: |
| 103 | |
| 104 | a.b.c.d.e.Cnum = 5; |
| 105 | // CHECK-NOT: error: |
| 106 | // CHECK: error:{{.*}} 'Cnum' |
| 107 | // CHECK-NOT: note: |
| 108 | // CHECK: note:{{.*}} 'Cnum' |
| 109 | // CHECK-NOT: note: |
| 110 | |
| 111 | a.getCB().c.d.e.num = 5; |
| 112 | // CHECK-NOT: error: |
| 113 | // CHECK: error:{{.*}} 'getCB' |
| 114 | // CHECK-NOT: note: |
| 115 | // CHECK: note:{{.*}} 'getCB' |
| 116 | // CHECK-NOT: note: |
| 117 | |
| 118 | a.getSCB().c.d.e.num = 5; |
| 119 | // CHECK-NOT: error: |
| 120 | // CHECK: error:{{.*}} 'getSCB' |
| 121 | // CHECK-NOT: note: |
| 122 | // CHECK: note:{{.*}} 'getSCB' |
| 123 | // CHECK-NOT: note: |
| 124 | } |
| 125 | |
| 126 | // Two notes |
| 127 | void test3(A a, const A Ca) { |
| 128 | |
| 129 | a.getSCB().Cc.d.e.num = 5; |
| 130 | // CHECK-NOT: error: |
| 131 | // CHECK: error:{{.*}} 'Cc' |
| 132 | // CHECK-NOT: note: |
| 133 | // CHECK: note:{{.*}} 'Cc' |
| 134 | // CHECK-NOT: note: |
| 135 | // CHECK: note:{{.*}} 'getSCB' |
| 136 | // CHECK-NOT: note: |
| 137 | |
| 138 | Ca.b.c.Cd.e.num = 5; |
| 139 | // CHECK-NOT: error: |
| 140 | // CHECK: error:{{.*}} 'Cd' |
| 141 | // CHECK-NOT: note: |
| 142 | // CHECK: note:{{.*}} 'Cd' |
| 143 | // CHECK-NOT: note: |
| 144 | // CHECK: note:{{.*}} 'Ca' |
| 145 | // CHECK-NOT: note: |
| 146 | |
| 147 | a.getCB().c.Cd.e.num = 5; |
| 148 | // CHECK-NOT: error: |
| 149 | // CHECK: error:{{.*}} 'Cd' |
| 150 | // CHECK-NOT: note: |
| 151 | // CHECK: note:{{.*}} 'Cd' |
| 152 | // CHECK-NOT: note: |
| 153 | // CHECK: note:{{.*}} 'getCB' |
| 154 | // CHECK-NOT: note: |
| 155 | |
| 156 | a.b.getCC().d.e.Cnum = 5; |
| 157 | // CHECK-NOT: error: |
| 158 | // CHECK: error:{{.*}} 'Cnum' |
| 159 | // CHECK-NOT: note: |
| 160 | // CHECK: note:{{.*}} 'Cnum' |
| 161 | // CHECK-NOT: note: |
| 162 | // CHECK: note:{{.*}} 'getCC' |
| 163 | // CHECK-NOT: note: |
| 164 | |
| 165 | a.b.c.Cd.Ce.num = 5; |
| 166 | // CHECK-NOT: error: |
| 167 | // CHECK: error:{{.*}} 'Ce' |
| 168 | // CHECK-NOT: note: |
| 169 | // CHECK: note:{{.*}} 'Ce' |
| 170 | // CHECK-NOT: note: |
| 171 | // CHECK: note:{{.*}} 'Cd' |
| 172 | // CHECK-NOT: note: |
| 173 | |
| 174 | a.b.CSc.Cd.e.num = 5; |
| 175 | // CHECK-NOT: error: |
| 176 | // CHECK: error:{{.*}} 'Cd' |
| 177 | // CHECK-NOT: note: |
| 178 | // CHECK: note:{{.*}} 'Cd' |
| 179 | // CHECK-NOT: note: |
| 180 | // CHECK: note:{{.*}} 'CSc' |
| 181 | // CHECK-NOT: note: |
| 182 | |
| 183 | a.CSb.c.Cd.e.num = 5; |
| 184 | // CHECK-NOT: error: |
| 185 | // CHECK: error:{{.*}} 'Cd' |
| 186 | // CHECK-NOT: note: |
| 187 | // CHECK: note:{{.*}} 'Cd' |
| 188 | // CHECK-NOT: note: |
| 189 | // CHECK: note:{{.*}} 'CSb' |
| 190 | // CHECK-NOT: note: |
| 191 | } |
| 192 | |
| 193 | // No errors |
| 194 | void test4(const A Ca) { |
| 195 | // Mutable cases |
| 196 | Ca.Mb.c.d.e.num = 5; |
| 197 | Ca.CSb.Mc.d.e.num = 5; |
| 198 | Ca.getCB().Mc.d.e.num = 5; |
| 199 | Ca.getSCB().Mc.d.e.num = 5; |
| 200 | |
| 201 | // Returning non-const reference |
| 202 | Ca.getB().c.d.e.num = 5; |
| 203 | Ca.CSb.getC().d.e.num = 5; |
| 204 | Ca.getCB().getC().d.e.num = 5; |
| 205 | Ca.getSCB().getC().d.e.num = 5; |
| 206 | |
| 207 | // Returning non-const reference |
| 208 | Ca.getSB().c.d.e.num = 5; |
| 209 | Ca.CSb.getSC().d.e.num = 5; |
| 210 | Ca.getCB().getSC().d.e.num = 5; |
| 211 | Ca.getSCB().getSC().d.e.num = 5; |
| 212 | |
| 213 | // Static member |
| 214 | Ca.Sb.c.d.e.num = 5; |
| 215 | Ca.CSb.Sc.d.e.num = 5; |
| 216 | Ca.getCB().Sc.d.e.num = 5; |
| 217 | Ca.getSCB().Sc.d.e.num = 5; |
| 218 | |
| 219 | // CHECK-NOT: error: |
| 220 | // CHECK-NOT: note: |
| 221 | } |
| 222 | |
| 223 | // Only display notes for relavent cases. |
| 224 | void test5(const A Ca) { |
| 225 | Ca.Mb.c.d.Ce.num = 5; |
| 226 | // CHECK-NOT: error: |
| 227 | // CHECK: error:{{.*}} 'Ce' |
| 228 | // CHECK-NOT: note: |
| 229 | // CHECK: note:{{.*}} 'Ce' |
| 230 | // CHECK-NOT: note: |
| 231 | |
| 232 | Ca.getB().c.d.Ce.num = 5; |
| 233 | // CHECK-NOT: error: |
| 234 | // CHECK: error:{{.*}} 'Ce' |
| 235 | // CHECK-NOT: note: |
| 236 | // CHECK: note:{{.*}} 'Ce' |
| 237 | // CHECK-NOT: note: |
| 238 | |
| 239 | Ca.getSB().c.d.Ce.num = 5; |
| 240 | // CHECK-NOT: error: |
| 241 | // CHECK: error:{{.*}} 'Ce' |
| 242 | // CHECK-NOT: note: |
| 243 | // CHECK: note:{{.*}} 'Ce' |
| 244 | // CHECK-NOT: note: |
| 245 | |
| 246 | Ca.Sb.c.d.Ce.num = 5; |
| 247 | // CHECK-NOT: error: |
| 248 | // CHECK: error:{{.*}} 'Ce' |
| 249 | // CHECK-NOT: note: |
| 250 | // CHECK: note:{{.*}} 'Ce' |
| 251 | // CHECK-NOT: note: |
| 252 | } |