[cfe-dev] [libc++]bitmask element ECMAScript is 0

Hubert Tong via cfe-dev cfe-dev at lists.llvm.org
Thu Oct 27 13:21:03 PDT 2016


On Thu, Oct 13, 2016 at 11:12 AM, Jason Liu via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> When I was browsing regex header from libcxx, I found the following code:
>
> enum syntax_option_type
>
> {
>
>     icase      = 1 << 0,
>
>     nosubs     = 1 << 1,
>
>     optimize   = 1 << 2,
>
>     collate    = 1 << 3,
>
>     ECMAScript = 0,
>
>     basic      = 1 << 4,
>
>     extended   = 1 << 5,
>
>     awk        = 1 << 6,
>
>     grep       = 1 << 7,
>
>     egrep      = 1 << 8
>
> };
>
>
> syntax_option_type is an implementation-defined bitmask type. According to
> standard, bitmask elements have distinct, nonzero values. And the value 0
> is used to represent an empty bitmask, in which no bitmask elements are
> set.
>
> Standard does mention that if no grammar element is set, the default
> grammar is ECMAScript. But ECMAScript still looks like a bitmask element
> inside of bitmask type syntax_option_type to me, which means it should be
> non-zero.
>
> Interestingly, when I look at the history of regex header, ECMAScript was
> a non-zero value at some point, but got changed to 0 in a later commit.
>
> So my questions are... Any reasons why we changed it to 0? (Maybe for
> cleaner implementation?) Is this still standard compliant? If not, should
> we modify it to be more standard compliant?
>
The use of "0" breaks use cases like the following:
bool isEcmaScript(::std::regex_constants::syntax_option_type v) {
  return v & ::std::regex_constants::ECMAScript;
}


> Thanks in advance!
>
>
> Regards,
>
>
> Jason Liu
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20161027/2e1b3997/attachment.html>


More information about the cfe-dev mailing list