From 196cc96f9a643d1cb828f48ef15ec30d0de24df7 Mon Sep 17 00:00:00 2001 From: Adam Czachorowski Date: Fri, 15 Jan 2021 18:37:25 +0100 Subject: [PATCH] [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 --- clang/lib/AST/DeclBase.cpp | 16 +++++++--------- clang/test/PCH/cxx-reference.h | 4 ++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 0656efa..dc59f3d 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(this) || - isa(this) || - isa(this) || - !getDeclContext() || - !isa(getDeclContext()) || - isInvalidDecl() || - isa(this) || - isa(this) || + // 8. it's a temporary with lifetime extended due to being default value. + if (isa(this) || isa(this) || + isa(this) || !getDeclContext() || + !isa(getDeclContext()) || isInvalidDecl() || + isa(this) || isa(this) || // FIXME: a ParmVarDecl can have ClassTemplateSpecialization // as DeclContext (?). isa(this) || // FIXME: a ClassTemplateSpecialization or CXXRecordDecl can have // AS_none as access specifier. isa(this) || - isa(this)) + isa(this) || + isa(this)) return true; assert(Access != AS_none && diff --git a/clang/test/PCH/cxx-reference.h b/clang/test/PCH/cxx-reference.h index b46a367..a65d3fe 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 +}; -- 2.7.4