Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8404445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:36:09+00:00 2026-06-09T22:36:09+00:00

Considering the C++11 function with the signaturer std::regex_match( std::string const&, std::smatch& match, std::regex const&

  • 0

Considering the C++11 function with the signaturer std::regex_match(
std::string const&, std::smatch& match, std::regex const& re )
, what
are the constraints on the lifetime of the first argument? I don’t find
any, but when I execute the following program (compiled with VC++ 2010,
iterator debugging active):

int
main()
{
    std::string a("aaa");
    std::string c("ccc");
    std::regex re("aaa(.*)ccc");
    std::smatch m;
    if (std::regex_match(a + "xyz" + c, m, re)) {
        std::cout << m[0] << std::endl;
        std::cout << m[1] << std::endl;
    }
    return 0;
}

it crashes, doubtlessly because the sub_match in m only keep
iterators into the string, and not copies. I can’t find anything in the
standard which forbids my code.

FWIW: it didn’t work in boost::regex, either, and that’s what the
std::regex is based on. (Of course, Boost didn’t document any
constraints with regards to the lifetime either.)

In the end, I guess my question is: should I send in a DR to the
standards organization, or a bug report to Microsoft?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:36:10+00:00Added an answer on June 9, 2026 at 10:36 pm

    I don’t recall any discussion of this possibility during the adoption of tr1::regex or std::regex, so I think it simply was not considered. In hindsight, it’s certainly a trap that we should have foreseen. Off the top of my head, an overload that takes a std::string&& would signal that a temporary is involved, and a copy is needed. So I’d report it to the Standards Committee. (full disclosure: I wrote the Dinkumware implementation, which is what Microsoft ships)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

considering the following function private static void GetText(String nodeValue) throws IOException { if(!file3.exists()) {
Considering this class Class 1 class myclass { public static function myfunction($condition, $string) {
Considering this code with 3 differents function call semantics: void f(void){ puts(OK); } int
Considering the code: <noscript><div>FOO</div></noscript> Running $('noscript').html(); returns &lt;div&gt;FOO&lt;/div&gt; but running $('noscript').text(); returns the raw
Considering following code public class A { public static void main(String[] args) { new
Considering the following PHP class: class someObject { public function broken(){ return isset($this->something()) ?
Considering the following as two versions of a very simple function in Python ,
I am considering to use a function that was introduced in an iPhone OS
When I use the constant argument of a function as a array size in
Considering this basic code snippet: <? class mcClassington { var $mcProperty='default'; function mcDoSomething() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.