Title
regex_iterator/regex_token_iterator should forbid temporary regexes
Status
c++14
Section
[re.iter]
Submitter
Stephan T. Lavavej

Created on 2013-09-21.00:00:00 last changed 123 months ago

Messages

Date: 2014-02-14.21:13:25

Proposed resolution:

This wording is relative to N3691.

  1. Change [re.regiter]/1, class template regex_iterator synopsis, as indicated:

    regex_iterator();
    regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
      const regex_type& re,
      regex_constants::match_flag_type m =
        regex_constants::match_default);
    regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
      const regex_type&& re,
      regex_constants::match_flag_type m =
        regex_constants::match_default) = delete;
    
  2. Change [re.tokiter]/6, class template regex_token_iterator synopsis, as indicated:

    regex_token_iterator();
    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
                         const regex_type& re,
                         int submatch = 0,
                         regex_constants::match_flag_type m =
                           regex_constants::match_default);
    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
                         const regex_type& re,
                         const std::vector<int>& submatches,
                         regex_constants::match_flag_type m =
                           regex_constants::match_default);
    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
                         const regex_type& re,
                         initializer_list<int> submatches,
                         regex_constants::match_flag_type m =
                           regex_constants::match_default);
    template <std::size_t N>
    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
                         const regex_type& re,
                         const int (&submatches)[N],
                         regex_constants::match_flag_type m =
                           regex_constants::match_default);
    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
                         const regex_type&& re,
                         int submatch = 0,
                         regex_constants::match_flag_type m =
                           regex_constants::match_default) = delete;
    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
                         const regex_type&& re,
                         const std::vector<int>& submatches,
                         regex_constants::match_flag_type m =
                           regex_constants::match_default) = delete;
    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
                         const regex_type&& re,
                         initializer_list<int> submatches,
                         regex_constants::match_flag_type m =
                           regex_constants::match_default) = delete;
    template <std::size_t N>
    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
                         const regex_type&& re,
                         const int (&submatches)[N],
                         regex_constants::match_flag_type m =
                           regex_constants::match_default) = delete;
    
Date: 2014-02-14.00:00:00

[ 2014-02-14 Issaquah meeting: Move to Immediate ]

Date: 2013-09-21.00:00:00

Users can write "for(sregex_iterator i(s.begin(), s.end(), regex("meow")), end; i != end; ++i)", binding a temporary regex to const regex& and storing a pointer to it. This will compile silently, triggering undefined behavior at runtime. We now have the technology to prevent this from compiling, like how reference_wrapper refuses to bind to temporaries.

History
Date User Action Args
2014-02-27 17:03:20adminsetstatus: wp -> c++14
2014-02-20 13:52:38adminsetstatus: immediate -> wp
2014-02-14 21:13:25adminsetmessages: + msg6871
2014-02-14 21:13:25adminsetstatus: new -> immediate
2013-10-12 21:02:13adminsetmessages: + msg6732
2013-09-21 00:00:00admincreate