Skip to content

Commit 8774b4b

Browse files
committed
[Clang] prevent recovery call expression from proceeding with explicit attributes and undeclared templates
1 parent 75d8724 commit 8774b4b

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ Bug Fixes to C++ Support
386386
- Fixed a crash in the typo correction of an invalid CTAD guide. (#GH107887)
387387
- Fixed a crash when clang tries to subtitute parameter pack while retaining the parameter
388388
pack. #GH63819, #GH107560
389-
389+
- Fixed an assertion failure when invoking recovery call expressions with explicit attributes
390+
and undeclared templates. (#GH107047, #GH49093)
390391

391392
Bug Fixes to AST Handling
392393
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4460,6 +4460,11 @@ ExprResult Sema::BuildTemplateIdExpr(const CXXScopeSpec &SS,
44604460
R.getAsSingle<ConceptDecl>(), TemplateArgs);
44614461
}
44624462

4463+
if (TemplateArgs && R.getAsSingle<FunctionDecl>() &&
4464+
R.getAsSingle<FunctionDecl>()->getTemplateSpecializationKind() ==
4465+
TemplateSpecializationKind::TSK_Undeclared)
4466+
return ExprError();
4467+
44634468
// We don't want lookup warnings at this point.
44644469
R.suppressDiagnostics();
44654470

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
2+
3+
namespace GH49093 {
4+
class B {
5+
public:
6+
static int a() { return 0; } // expected-note {{member is declared here}}
7+
decltype(a< 0 >(0)) test; // expected-error {{member 'a' used before its declaration}}
8+
};
9+
10+
struct C {
11+
static int a() { return 0; } // expected-note {{member is declared here}}
12+
decltype(a < 0 > (0)) test; // expected-error {{member 'a' used before its declaration}}
13+
};
14+
15+
void test_is_bool(bool t) {}
16+
void test_is_bool(int t) {}
17+
18+
int main() {
19+
B b;
20+
test_is_bool(b.test);
21+
22+
C c;
23+
test_is_bool(c.test);
24+
}
25+
}
26+
27+
namespace GH107047 {
28+
struct A {
29+
static constexpr auto test() { return 1; } // expected-note {{member is declared here}}
30+
static constexpr int s = test< 1 >(); // expected-error {{member 'test' used before its declaration}}
31+
};
32+
}

0 commit comments

Comments
 (0)