July 14, 2023
https://issues.dlang.org/show_bug.cgi?id=24047

          Issue ID: 24047
           Summary: compiler accepts unparseable code for unittests when
                    -unittest is not provided
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Keywords: accepts-invalid
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: schveiguy@gmail.com

without -unittest switch, this compiles:

```d
unittest anything goes here, even open parentheses without matching ones: (((((
{
   stuff in here can be complete garbage as well???!!!
}
```

The grammar states that Unittest should be:

```
Unittest:
    unittest BlockStatement
```

So really, nothing but whitespace should be allowed between the `unittest` keyword and the opening brace, and the block statement should be valid D grammar.

I get that the unittest itself can be skipped, and while I can understand a small benefit from avoiding the parsing of the function itself, I don't believe there's any other place where unparseable text is allowed. Even with templates that aren't instantiated, or inside version(none) blocks.

I believe the code above should not compile, even when -unittest is not specified.

--