[clang] Allow LifetimeExtendedTemporary to have no access specifier

The check only runs in debug mode during serialization, but
assert()-fail on:
  struct S { const int& x = 7; };
in C++ mode.

Differential Revision: https://reviews.llvm.org/D94804
This commit is contained in:
Adam Czachorowski 2021-01-15 18:37:25 +01:00
parent 23b0ab2acb
commit 196cc96f9a
2 changed files with 11 additions and 9 deletions

View File

@ -971,21 +971,19 @@ bool Decl::AccessDeclContextSanity() const {
// 5. it's invalid
// 6. it's a C++0x static_assert.
// 7. it's a block literal declaration
if (isa<TranslationUnitDecl>(this) ||
isa<TemplateTypeParmDecl>(this) ||
isa<NonTypeTemplateParmDecl>(this) ||
!getDeclContext() ||
!isa<CXXRecordDecl>(getDeclContext()) ||
isInvalidDecl() ||
isa<StaticAssertDecl>(this) ||
isa<BlockDecl>(this) ||
// 8. it's a temporary with lifetime extended due to being default value.
if (isa<TranslationUnitDecl>(this) || isa<TemplateTypeParmDecl>(this) ||
isa<NonTypeTemplateParmDecl>(this) || !getDeclContext() ||
!isa<CXXRecordDecl>(getDeclContext()) || isInvalidDecl() ||
isa<StaticAssertDecl>(this) || isa<BlockDecl>(this) ||
// FIXME: a ParmVarDecl can have ClassTemplateSpecialization
// as DeclContext (?).
isa<ParmVarDecl>(this) ||
// FIXME: a ClassTemplateSpecialization or CXXRecordDecl can have
// AS_none as access specifier.
isa<CXXRecordDecl>(this) ||
isa<ClassScopeFunctionSpecializationDecl>(this))
isa<ClassScopeFunctionSpecializationDecl>(this) ||
isa<LifetimeExtendedTemporaryDecl>(this))
return true;
assert(Access != AS_none &&

View File

@ -11,3 +11,7 @@ LR &lrlr = c;
LR &&rrlr = c;
RR &lrrr = c;
RR &&rrrr = 'c';
struct S {
const int &x = 1; // LifetimeExtendedTemporary inside struct
};