Skip to content

Commit 035daf5

Browse files
Endilllyuxuanchen1997
authored andcommitted
[clang] Fix crash in concept deprecation (#98622)
Summary: There is a gap between `getAs<AutoType>()` and `getConstrainedAutoType()` that the original patch #92295 was not aware of. Fixes #98164 Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250794
1 parent 4168185 commit 035daf5

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7436,10 +7436,10 @@ NamedDecl *Sema::ActOnVariableDeclarator(
74367436
tryToFixVariablyModifiedVarType(TInfo, R, D.getIdentifierLoc(),
74377437
/*DiagID=*/0);
74387438

7439-
if (const AutoType *AutoT = R->getAs<AutoType>())
7440-
CheckConstrainedAuto(
7441-
AutoT,
7442-
TInfo->getTypeLoc().getContainedAutoTypeLoc().getConceptNameLoc());
7439+
if (AutoTypeLoc TL = TInfo->getTypeLoc().getContainedAutoTypeLoc()) {
7440+
const AutoType *AT = TL.getTypePtr();
7441+
CheckConstrainedAuto(AT, TL.getConceptNameLoc());
7442+
}
74437443

74447444
bool IsMemberSpecialization = false;
74457445
bool IsVariableTemplateSpecialization = false;

clang/lib/Sema/SemaType.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6363,11 +6363,10 @@ TypeResult Sema::ActOnTypeName(Declarator &D) {
63636363
CheckExtraCXXDefaultArguments(D);
63646364
}
63656365

6366-
if (const AutoType *AutoT = T->getAs<AutoType>())
6367-
CheckConstrainedAuto(
6368-
AutoT,
6369-
TInfo->getTypeLoc().getContainedAutoTypeLoc().getConceptNameLoc());
6370-
6366+
if (AutoTypeLoc TL = TInfo->getTypeLoc().getContainedAutoTypeLoc()) {
6367+
const AutoType *AT = TL.getTypePtr();
6368+
CheckConstrainedAuto(AT, TL.getConceptNameLoc());
6369+
}
63716370
return CreateParsedType(T, TInfo);
63726371
}
63736372

clang/test/CXX/drs/cwg24xx.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ auto h() -> C auto {
8282
C auto foo = T();
8383
// expected-warning@-1 {{'C' is deprecated}}
8484
// expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}}
85+
C auto *bar = T();
86+
// expected-warning@-1 {{'C' is deprecated}}
87+
// expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}}
88+
C auto &baz = T();
89+
// expected-warning@-1 {{'C' is deprecated}}
90+
// expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}}
91+
C auto &&quux = T();
92+
// expected-warning@-1 {{'C' is deprecated}}
93+
// expected-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}}
8594
return foo;
8695
}
8796
#endif

clang/test/SemaCXX/cxx-deprecated.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,13 @@ template <C T>
3636
// expected-warning@-1 {{'C' is deprecated}}
3737
// expected-note@#C {{'C' has been explicitly marked deprecated here}}
3838
void f();
39+
40+
namespace GH98164 {
41+
template <int>
42+
auto b() = delete; // #b
43+
44+
decltype(b<0>()) x;
45+
// expected-error@-1 {{call to deleted function 'b'}}
46+
// expected-note@#b {{candidate function [with $0 = 0] has been explicitly deleted}}
47+
} // namespace GH98164
3948
} // namespace cxx20_concept

0 commit comments

Comments
 (0)