[-Wempty-character-class]ΒΆ

This warning is complementary to --empty-class option. The option expects a single argument, one of the following:

  • match-empty (default): empty character class matches empty string (that is, always matches and consumes no code units). This attitude is strange; however, some real-world programs rely on it.
  • match-none: empty character class never matches. This is what logic suggests.
  • error: empty character class is an error.

The [-Wempty-character-class] warning is a reminder for those who are not aware of --empty-class option.

Note that empty character class can be constructed in many ways:

1
2
3
4
5
6
7
/*!re2c
    []                        { return 0; }
    [^\x00-\xFF]              { return 1; }
    [^] \ [^]                 { return 2; }
    [abc] \ ("a" | "b" | "c") { return 3; }
    "a" \ [a-z]               { return 4; }
*/

Given this code, `re2c -i -Wempty-character-class` generates:

1
2
3
4
5
6
/* Generated by re2c 0.14.1.dev on Wed Nov 11 11:42:00 2015*/

{
        YYCTYPE yych;
        { return 0; }
}

And warns:

re2c: warning: line 2: empty character class [-Wempty-character-class]
re2c: warning: line 3: empty character class [-Wempty-character-class]
re2c: warning: line 4: empty character class [-Wempty-character-class]
re2c: warning: line 5: empty character class [-Wempty-character-class]
re2c: warning: line 6: empty character class [-Wempty-character-class]