[clang] 196cc96 - [clang] Allow LifetimeExtendedTemporary to have no access specifier
Adam Czachorowski via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 18 10:29:48 PST 2021
Author: Adam Czachorowski
Date: 2021-01-18T19:19:57+01:00
New Revision: 196cc96f9a643d1cb828f48ef15ec30d0de24df7
URL: https://github.com/llvm/llvm-project/commit/196cc96f9a643d1cb828f48ef15ec30d0de24df7
DIFF: https://github.com/llvm/llvm-project/commit/196cc96f9a643d1cb828f48ef15ec30d0de24df7.diff
LOG: [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
Added:
Modified:
clang/lib/AST/DeclBase.cpp
clang/test/PCH/cxx-reference.h
Removed:
################################################################################
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 0656efae5489..dc59f3dd1f15 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -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 &&
diff --git a/clang/test/PCH/cxx-reference.h b/clang/test/PCH/cxx-reference.h
index b46a3671a325..a65d3feee072 100644
--- a/clang/test/PCH/cxx-reference.h
+++ b/clang/test/PCH/cxx-reference.h
@@ -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
+};
More information about the cfe-commits
mailing list