[-Wempty-character-class]ΒΆ

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

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

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

Note that an 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]