Genivia / RE-flex

A high-performance C++ regex library and lexical analyzer generator with Unicode support. Extends Flex++ with Unicode support, indent/dedent anchors, lazy quantifiers, functions for lex and syntax error reporting and more. Seamlessly integrates with Bison and other parsers.
https://www.genivia.com/doc/reflex/html
BSD 3-Clause "New" or "Revised" License
504 stars 85 forks source link

MSVC error 2229 #202

Closed Albertweiku closed 5 months ago

Albertweiku commented 5 months ago

Generation method:

The problem is that the resulting header file contains a large number of structure or bit fields whose members contain an array of size zero, but that is not the last member. This causes errors when compiling with msvc.

https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2229?view=msvc-170

genivia-inc commented 5 months ago

OK, but do you have an example lexer input file for us to replicate the problem so we can fix it? That would help. Without a test case we can only guess, since the tool and the output generation has lots of options.

The generated header file declares the yyFlexLexer class with yylex() method and nothing else, no structures, no bit fields and no zero length arrays, at least not by default and not with the usual options.

So again, please provide more details when this happens.

Albertweiku commented 5 months ago

image image image

Even if I use a near-empty lex file to generate the header file, it has an array of declared size 0.This seems to be a disallowed behavior in MSVC. Is it because there is a problem with my options?

genivia-inc commented 5 months ago

That output is generated with option -p. These arrays track the performance of every lexer rule. If there are no rules specified, then these arrays are empty.

This never happens with normal lexer specifications that have at least one rule. Lexer specifications that do not have rules are not useful.

Perhaps the reflex tool should just bail out with an error and not generate any code when no rules are specified.

On the other hand, just removing these empty array declarations from the output works fine too. Perhaps something to do for the next release update, it's just easy to work around by adding a guard like so in src/reflex.cpp:2399:

      if (report > 0) // skip when zero: no rules specified
      {
        *out <<
          "  size_t perf_report_" << conditions[start] << "_rule[" << report << "];\n"
          "  size_t perf_report_" << conditions[start] << "_size[" << report << "];\n"
          "  float  perf_report_" << conditions[start] << "_time[" << report << "];\n";
      }