1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -Wunreachable-code-aggressive -fblocks -verify %s 2f4a2713aSLionel Sambuc 3f4a2713aSLionel Sambuc int j; 4*0a6a1f1dSLionel Sambuc int bar(); test1()5f4a2713aSLionel Sambucint test1() { 6f4a2713aSLionel Sambuc for (int i = 0; 7f4a2713aSLionel Sambuc i != 10; 8*0a6a1f1dSLionel Sambuc ++i) { // expected-warning {{loop will run at most once (loop increment never executed)}} 9f4a2713aSLionel Sambuc if (j == 23) // missing {}'s 10f4a2713aSLionel Sambuc bar(); 11f4a2713aSLionel Sambuc return 1; 12f4a2713aSLionel Sambuc } 13f4a2713aSLionel Sambuc return 0; 14f4a2713aSLionel Sambuc return 1; // expected-warning {{will never be executed}} 15f4a2713aSLionel Sambuc } 16f4a2713aSLionel Sambuc test1_B()17*0a6a1f1dSLionel Sambucint test1_B() { 18*0a6a1f1dSLionel Sambuc for (int i = 0; 19*0a6a1f1dSLionel Sambuc i != 10; 20*0a6a1f1dSLionel Sambuc ++i) { // expected-warning {{loop will run at most once (loop increment never executed)}} 21*0a6a1f1dSLionel Sambuc if (j == 23) // missing {}'s 22*0a6a1f1dSLionel Sambuc bar(); 23*0a6a1f1dSLionel Sambuc return 1; 24*0a6a1f1dSLionel Sambuc } 25*0a6a1f1dSLionel Sambuc return 0; 26*0a6a1f1dSLionel Sambuc return bar(); // expected-warning {{will never be executed}} 27*0a6a1f1dSLionel Sambuc } 28*0a6a1f1dSLionel Sambuc test2(int i)29f4a2713aSLionel Sambucvoid test2(int i) { 30f4a2713aSLionel Sambuc switch (i) { 31f4a2713aSLionel Sambuc case 0: 32f4a2713aSLionel Sambuc break; 33f4a2713aSLionel Sambuc bar(); // expected-warning {{will never be executed}} 34f4a2713aSLionel Sambuc case 2: 35f4a2713aSLionel Sambuc switch (i) { 36f4a2713aSLionel Sambuc default: 37f4a2713aSLionel Sambuc a: goto a; 38f4a2713aSLionel Sambuc } 39f4a2713aSLionel Sambuc bar(); // expected-warning {{will never be executed}} 40f4a2713aSLionel Sambuc } 41f4a2713aSLionel Sambuc b: goto b; 42f4a2713aSLionel Sambuc bar(); // expected-warning {{will never be executed}} 43f4a2713aSLionel Sambuc } 44f4a2713aSLionel Sambuc test3()45f4a2713aSLionel Sambucvoid test3() { 46f4a2713aSLionel Sambuc ^{ return; 47f4a2713aSLionel Sambuc bar(); // expected-warning {{will never be executed}} 48f4a2713aSLionel Sambuc }(); 49f4a2713aSLionel Sambuc while (++j) { 50f4a2713aSLionel Sambuc continue; 51f4a2713aSLionel Sambuc bar(); // expected-warning {{will never be executed}} 52f4a2713aSLionel Sambuc } 53f4a2713aSLionel Sambuc } 54f4a2713aSLionel Sambuc 55f4a2713aSLionel Sambuc // PR 6130 - Don't warn about bogus unreachable code with throw's and 56f4a2713aSLionel Sambuc // temporary objects. 57f4a2713aSLionel Sambuc class PR6130 { 58f4a2713aSLionel Sambuc public: 59f4a2713aSLionel Sambuc PR6130(); 60f4a2713aSLionel Sambuc ~PR6130(); 61f4a2713aSLionel Sambuc }; 62f4a2713aSLionel Sambuc pr6130(unsigned i)63f4a2713aSLionel Sambucint pr6130(unsigned i) { 64f4a2713aSLionel Sambuc switch(i) { 65f4a2713aSLionel Sambuc case 0: return 1; 66f4a2713aSLionel Sambuc case 1: return 2; 67f4a2713aSLionel Sambuc default: 68f4a2713aSLionel Sambuc throw PR6130(); // no-warning 69f4a2713aSLionel Sambuc } 70f4a2713aSLionel Sambuc } 71