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

fix #11691: FP throwInNoexceptFunction with if constexpr in template #6962

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ludviggunne
Copy link
Contributor

No description provided.

@ludviggunne ludviggunne changed the title fix #11691 fix #11691: FP throwInNoexceptFunction with if constexpr in template Oct 27, 2024
tok = tok->astParent();
const Token *condTok = tok->astOperand2();
// check if condition is possibly false, since template arguments are not set to known
if (isPossibleBool(condTok, false)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow we should check if the possible values are template arguments. You can check Token::templateArg for "possible" operands .

If the condition is false you skip the if-body but if the condition is true you do nothing, you should skip the else body then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The utility function I introduce in #7045 would be useful for this, so maybe I should wait for that one.

if (Token::simpleMatch(tok, "{"))
tok = tok->link();
else while (tok && !Token::simpleMatch(tok, ";"))
tok = tok->next();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not seem to be formatted properly. we have the runformat script in the cppcheck folder could you run that..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this seems to be what uncrustify wants. But I could add braces to make it more readable.


// #11691: FP throwInNoexceptFunction with if constexpr in template
check("template<bool IsNoThrow>\n"
"static void* MyNew(size_t Size) noexcept(IsNoThrow) {\n"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test case can be reduced:

template<bool IsNoThrow>
static void foo(size_t Size) noexcept(IsNoThrow) {
    if constexpr (!IsNoThrow) {
        throw std::bad_alloc();
    }
}

foo<true>(123);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants