Skip to content

Commit f347483

Browse files
Fix #13803 FP throwInNoexceptFunction when taking address of function (danmar#7486)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent 4314496 commit f347483

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/checkexceptionsafety.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ static const Token * functionThrowsRecursive(const Function * function, std::set
257257
tok = tok->linkAt(1); // skip till start of catch clauses
258258
if (tok->str() == "throw")
259259
return tok;
260-
if (tok->function()) {
260+
if (tok->function() && Token::simpleMatch(tok->astParent(), "(")) {
261261
const Function * called = tok->function();
262262
// check if called function has an exception specification
263263
if (called->isThrow() && called->throwArg)

test/testexceptionsafety.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class TestExceptionSafety : public TestFixture {
5656
TEST_CASE(rethrowNoCurrentException1);
5757
TEST_CASE(rethrowNoCurrentException2);
5858
TEST_CASE(rethrowNoCurrentException3);
59+
TEST_CASE(noFunctionCall);
5960
}
6061

6162
struct CheckOptions
@@ -479,6 +480,16 @@ class TestExceptionSafety : public TestFixture {
479480
"void func3() { throw 0; }");
480481
ASSERT_EQUALS("", errout_str());
481482
}
483+
484+
void noFunctionCall() {
485+
check("void f() {\n" // #13803
486+
" throw \"error\";\n"
487+
"}\n"
488+
"void g() noexcept {\n"
489+
" auto pF = &f;\n"
490+
"}\n");
491+
ASSERT_EQUALS("", errout_str());
492+
}
482493
};
483494

484495
REGISTER_TEST(TestExceptionSafety)

0 commit comments

Comments
 (0)