|
1 | 1 | // RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -Wno-c++1y-extensions -verify %s
|
2 |
| -// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -Wno-c++1y-extensions -verify -std=c++11 %s |
| 2 | +// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -Wno-c++14-extensions -Wno-c++17-extensions -verify -std=c++11 %s |
3 | 3 | template<typename T> void f() {
|
4 | 4 | T t;
|
5 | 5 | t = 17;
|
@@ -294,3 +294,115 @@ void RAIIWrapperTest() {
|
294 | 294 | }
|
295 | 295 |
|
296 | 296 | } // namespace gh54489
|
| 297 | + |
| 298 | +namespace inside_condition { |
| 299 | + void ifs() { |
| 300 | + if (int hoge = 0) // expected-warning {{unused variable 'hoge'}} |
| 301 | + return; |
| 302 | + if (const int const_hoge = 0) // expected-warning {{unused variable 'const_hoge'}} |
| 303 | + return; |
| 304 | + else if (int fuga = 0) |
| 305 | + (void)fuga; |
| 306 | + else if (int used = 1; int catched = used) // expected-warning {{unused variable 'catched'}} |
| 307 | + return; |
| 308 | + else if (int refed = 1; int used = refed) |
| 309 | + (void)used; |
| 310 | + else if (int unused1 = 2; int unused2 = 3) // expected-warning {{unused variable 'unused1'}} \ |
| 311 | + // expected-warning {{unused variable 'unused2'}} |
| 312 | + return; |
| 313 | + else if (int unused = 4; int used = 5) // expected-warning {{unused variable 'unused'}} |
| 314 | + (void)used; |
| 315 | + else if (int used = 6; int unused = 7) // expected-warning {{unused variable 'unused'}} |
| 316 | + (void)used; |
| 317 | + else if (int used1 = 8; int used2 = 9) |
| 318 | + (void)(used1 + used2); |
| 319 | + else if (auto [a, b] = (int[2]){ 1, 2 }; 1) // expected-warning {{unused variable '[a, b]'}} |
| 320 | + return; |
| 321 | + else if (auto [a, b] = (int[2]){ 1, 2 }; a) |
| 322 | + return; |
| 323 | + } |
| 324 | + |
| 325 | + void fors() { |
| 326 | + for (int i = 0;int unused = 0;); // expected-warning {{unused variable 'i'}} \ |
| 327 | + // expected-warning {{unused variable 'unused'}} |
| 328 | + for (int i = 0;int used = 0;) // expected-warning {{unused variable 'i'}} |
| 329 | + (void)used; |
| 330 | + while(int var = 1) // expected-warning {{unused variable 'var'}} |
| 331 | + return; |
| 332 | + } |
| 333 | + |
| 334 | + void whiles() { |
| 335 | + while(int unused = 1) // expected-warning {{unused variable 'unused'}} |
| 336 | + return; |
| 337 | + while(int used = 1) |
| 338 | + (void)used; |
| 339 | + } |
| 340 | + |
| 341 | + |
| 342 | + void switches() { |
| 343 | + switch(int unused = 1) { // expected-warning {{unused variable 'unused'}} |
| 344 | + case 1: return; |
| 345 | + } |
| 346 | + switch(constexpr int used = 3; int unused = 4) { // expected-warning {{unused variable 'unused'}} |
| 347 | + case used: return; |
| 348 | + } |
| 349 | + switch(int used = 3; int unused = 4) { // expected-warning {{unused variable 'unused'}} |
| 350 | + case 3: (void)used; |
| 351 | + } |
| 352 | + switch(constexpr int used1 = 0; constexpr int used2 = 6) { |
| 353 | + case (used1+used2): return; |
| 354 | + } |
| 355 | + switch(auto [a, b] = (int[2]){ 1, 2 }; 1) { // expected-warning {{unused variable '[a, b]'}} |
| 356 | + case 1: return; |
| 357 | + } |
| 358 | + switch(auto [a, b] = (int[2]){ 1, 2 }; b) { |
| 359 | + case 1: return; |
| 360 | + } |
| 361 | + switch(auto [a, b] = (int[2]){ 1, 2 }; 1) { |
| 362 | + case 1: (void)a; |
| 363 | + } |
| 364 | + } |
| 365 | + template <typename T> |
| 366 | + struct Vector { |
| 367 | + void doIt() { |
| 368 | + for (auto& e : elements){} // expected-warning {{unused variable 'e'}} |
| 369 | + } |
| 370 | + T elements[10]; |
| 371 | + }; |
| 372 | + void ranged_for() { |
| 373 | + Vector<int> vector; |
| 374 | + vector.doIt(); // expected-note {{here}} |
| 375 | + } |
| 376 | + |
| 377 | + |
| 378 | + struct RAII { |
| 379 | + int &x; |
| 380 | + RAII(int &ref) : x(ref) {} |
| 381 | + ~RAII() { x = 0;} |
| 382 | + operator int() const { return 1; } |
| 383 | + }; |
| 384 | + void aggregate() { |
| 385 | + int x = 10; |
| 386 | + int y = 10; |
| 387 | + if (RAII var = x) {} |
| 388 | + for(RAII var = x; RAII var2 = y;) {} |
| 389 | + while (RAII var = x) {} |
| 390 | + switch (RAII var = x) {} |
| 391 | + } |
| 392 | + |
| 393 | + struct TrivialDtor{ |
| 394 | + int &x; |
| 395 | + TrivialDtor(int &ref) : x(ref) { ref = 32; } |
| 396 | + operator int() const { return 1; } |
| 397 | + }; |
| 398 | + void trivial_dtor() { |
| 399 | + int x = 10; |
| 400 | + int y = 10; |
| 401 | + if (TrivialDtor var = x) {} // expected-warning {{unused variable 'var'}} |
| 402 | + for(TrivialDtor var = x; TrivialDtor var2 = y;) {} // expected-warning {{unused variable 'var'}} \ |
| 403 | + // expected-warning {{unused variable 'var2'}} |
| 404 | + while (TrivialDtor var = x) {} // expected-warning {{unused variable 'var'}} |
| 405 | + switch (TrivialDtor var = x) {} // expected-warning {{unused variable 'var'}} |
| 406 | + } |
| 407 | + |
| 408 | +} // namespace inside_condition |
0 commit comments