Fix 10532, 14835, 20522 by adding test cases

This commit is contained in:
Dennis Korpel 2023-09-21 14:48:30 +02:00
parent f4fd327616
commit cfd7cfd438
3 changed files with 48 additions and 1 deletions

View file

@ -155,7 +155,7 @@ int blockExit(Statement s, FuncDeclaration func, ErrorSink eSink)
{
import dmd.errorsink : DiagnosticFlag;
version (none) // this warning is completely useless due to insane false positive rate in real life template code
if (blockExit(s, func, mustNotThrow) != BE.halt && s.hasCode() &&
if (blockExit(s, func, eSink) != BE.halt && s.hasCode() &&
s.loc != Loc.initial) // don't emit warning for generated code
global.errorSink.warning(DiagnosticFlag.unreachable, s.loc, "statement is not reachable");
}

View file

@ -71,3 +71,27 @@ void test3()
finally foo();
int x = 1;
}
// https://issues.dlang.org/show_bug.cgi?id=14835
bool isEven(int i)()
{
static if (i % 2)
return true;
return false;
}
enum x = isEven!0;
// https://issues.dlang.org/show_bug.cgi?id=10532
alias Seq(T...) = T;
void f()
{
foreach (e; Seq!(10, 20))
{
if (e == 10)
continue;
// lots of code follows..
auto x = 1;
}
}

View file

@ -0,0 +1,23 @@
/*
REQUIRED_ARGS: -w
TEST_OUTPUT:
---
fail_compilation/test20522.d(19): Error: undefined identifier `non_existent`
---
*/
// https://issues.dlang.org/show_bug.cgi?id=20522
struct File
{
~this() {}
}
void main()
{
{
auto test = File(); // <- Essential
non_existent;
}
// Warning: statement is not reachable
string[] is_this_unreachable_question_mark;
}