Skip to content

Commit 1fa3c85

Browse files
authored
[Clang] prevent recovery call expression from proceeding with explicit attributes and undeclared templates (#107786)
Fixes #107047 Fixes #49093
1 parent 741ad3a commit 1fa3c85

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ Bug Fixes to C++ Support
489489
- Clang now instantiates the correct lambda call operator when a lambda's class type is
490490
merged across modules. (#GH110401)
491491
- Fix a crash when parsing a pseudo destructor involving an invalid type. (#GH111460)
492+
- Fixed an assertion failure when invoking recovery call expressions with explicit attributes
493+
and undeclared templates. (#GH107047, #GH49093)
492494

493495
Bug Fixes to AST Handling
494496
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaExpr.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2470,7 +2470,15 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
24702470
LookupCtx ? LookupCtx : (SS.isEmpty() ? CurContext : nullptr);
24712471
while (DC) {
24722472
if (isa<CXXRecordDecl>(DC)) {
2473-
LookupQualifiedName(R, DC);
2473+
if (ExplicitTemplateArgs) {
2474+
if (LookupTemplateName(
2475+
R, S, SS, Context.getRecordType(cast<CXXRecordDecl>(DC)),
2476+
/*EnteringContext*/ false, TemplateNameIsRequired,
2477+
/*RequiredTemplateKind*/ nullptr, /*AllowTypoCorrection*/ true))
2478+
return true;
2479+
} else {
2480+
LookupQualifiedName(R, DC);
2481+
}
24742482

24752483
if (!R.empty()) {
24762484
// Don't give errors about ambiguities in this lookup.
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 {{declared as a non-template here}}
7+
decltype(a< 0 >(0)) test; // expected-error {{'a' does not refer to a template}}
8+
};
9+
10+
struct C {
11+
static int a() { return 0; } // expected-note {{declared as a non-template here}}
12+
decltype(a < 0 > (0)) test; // expected-error {{'a' does not refer to a template}}
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 {{declared as a non-template here}}
30+
static constexpr int s = test< 1 >(); // expected-error {{'test' does not refer to a template}}
31+
};
32+
}

0 commit comments

Comments
 (0)