<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3604: What is the effect of an invalid value of type syntax_option_type?</title>
<meta property="og:title" content="Issue 3604: What is the effect of an invalid value of type syntax_option_type?">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3604.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#New">New</a> status.</em></p>
<h3 id="3604"><a href="lwg-active.html#3604">3604</a>. What is the effect of an invalid value of type <code>syntax_option_type</code>?</h3>
<p><b>Section:</b> 28.6.7.2 <a href="https://wg21.link/re.regex.construct">[re.regex.construct]</a>, 28.6.4.2 <a href="https://wg21.link/re.synopt">[re.synopt]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2021-09-27 <b>Last modified:</b> 2021-10-14</p>
<p><b>Priority: </b>3
</p>
<p><b>View other</b> <a href="lwg-index-open.html#re.regex.construct">active issues</a> in [re.regex.construct].</p>
<p><b>View all other</b> <a href="lwg-index.html#re.regex.construct">issues</a> in [re.regex.construct].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
28.6.4.2 <a href="https://wg21.link/re.synopt">[re.synopt]</a> says:
</p>
<blockquote><p>
A valid value of type <code>syntax_option_type</code> shall have at most one of the grammar elements <code>ECMAScript</code>, 
<code>basic</code>, <code>extended</code>, <code>awk</code>, <code>grep</code>, <code>egrep</code>, set.
</p></blockquote>
<p>
But then we never say what happens if an invalid value is used.
<p/>
What does <code>std::regex(".", std::regex::grep|std::regex::awk)</code> do? Is it undefined? Does it throw?
<p/>
It seems reasonable for <code>basic_regex</code> constructors to throw if <code>f</code> is not a valid value, i.e. 
for each non-default constructor:
</p>
<blockquote><p>
<i>Throws:</i> <code>regex_error</code> <ins>if <code>f</code> is not a valid value, or</ins> if [&hellip;] is not a valid 
regular expression according to the grammar specified by <code>f</code>.
</p></blockquote>
<p>
However, there is no <code>regex_constants::error_code</code> value suitable for this error condition.
<p/>
Also, the constructors say "<i>Postconditions:</i> <code>flags()</code> returns <code>f</code>." This prevents an 
implementation from storing <code>f|ECMAScript</code> in <code>flags()</code> if no grammar element is present in <code>f</code>. 
This seems like an unnecessary restriction, and forces implementations to do extra work to check if the 
<code>ECMAScript</code> grammar is in use. Arguably, it would even be better to require implementations to set 
<code>ECMAScript</code> in <code>flags()</code> if no grammar element was set in the flags passed to the constructor.
This problem was introduced by LWG <a href="lwg-defects.html#2330" title="regex(&quot;meow&quot;, regex::icase) is technically forbidden but should be permitted (Status: C++14)">2330</a><sup><a href="https://cplusplus.github.io/LWG/issue2330" title="Latest snapshot">(i)</a></sup>.
</p>

<p><i>[2021-10-14; Reflector poll]</i></p>

<p>
Set priority to 3 after reflector poll.
</p>



<p id="res-3604"><b>Proposed resolution:</b></p>





</body>
</html>
