Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<regex>: Goofy message for error_badbrace #4993

Closed
Alcaro opened this issue Sep 30, 2024 · 7 comments · Fixed by #5025
Closed

<regex>: Goofy message for error_badbrace #4993

Alcaro opened this issue Sep 30, 2024 · 7 comments · Fixed by #5025
Labels
enhancement Something can be improved fixed Something works now, yay! good first issue Good for newcomers

Comments

@Alcaro
Copy link
Contributor

Alcaro commented Sep 30, 2024

Describe the bug

The error_badbrace string is significantly goofy looking

Command-line test case

#include <regex>

int main()
{
    try {
        std::regex r("a{4,3}");
        puts("it's legal");
    } catch (std::exception& e) {
        puts(e.what());
    }
}

https://godbolt.org/z/Y14Exavx7

Expected behavior

The expression contained an invalid range in a {} expression.

Actual behavior

The expression contained an invalid range in a { expression }.

Why was the closing brace moved one word to the right? That's neither consistent with the C++ spec, nor with my understanding of English grammar.

STL version

Don't know, ask Godbolt

Additional context

Probably a good first issue Good for newcomers

@fsb4000
Copy link
Contributor

fsb4000 commented Sep 30, 2024

Yes, I agree.
Code:

STL/stl/inc/regex

Lines 500 to 502 in faccf00

case regex_constants::error_badbrace:
return "regex_error(error_badbrace): The expression "
"contained an invalid range in a { expression }.";

Why was the closing brace moved one word to the right?

Probably a copy-paste error. Look at the messages above:

STL/stl/inc/regex

Lines 491 to 499 in faccf00

case regex_constants::error_brack:
return "regex_error(error_brack): The expression "
"contained mismatched [ and ].";
case regex_constants::error_paren:
return "regex_error(error_paren): The expression "
"contained mismatched ( and ).";
case regex_constants::error_brace:
return "regex_error(error_brace): The expression "
"contained mismatched { and }.";

https://godbolt.org/z/rKrbha61c
https://godbolt.org/z/bMdzrEhnv
https://godbolt.org/z/c8x4oTGEx

Click to expand unrelated discussion of other regex behavior:

By the way, we found a bug in the GCC standard library. I will check if that bug has been reported by someone; if not, I will create an issue.
An example with the bug: https://godbolt.org/z/c8x4oTGEx

@Alcaro

This comment was marked as off-topic.

@fsb4000

This comment was marked as off-topic.

@CaseyCarter CaseyCarter added enhancement Something can be improved good first issue Good for newcomers labels Sep 30, 2024
@fsb4000

This comment was marked as off-topic.

@fsb4000

This comment was marked as off-topic.

@StephanTLavavej
Copy link
Member

We talked about this at the weekly maintainer meeting and we agree that the error message can be easily improved.

@fsb4000 As this issue is about the error_badbrace message, discussion of other potential bugs should be done in a separate issue to avoid confusion. This is a good general principle to follow, but especially in things marked good first issue Good for newcomers which should be easy for new contributors to read and understand. Accordingly I'm going to collapse the unrelated comments.

@FranciscoThiesen
Copy link

Will take a look into fixing this!

5AIPAVAN added a commit to 5AIPAVAN/STL that referenced this issue Oct 17, 2024
@StephanTLavavej StephanTLavavej added the fixed Something works now, yay! label Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something can be improved fixed Something works now, yay! good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants