adamcz created this revision. adamcz added a reviewer: hokein. adamcz requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
The check only runs in debug mode during serialization, but assert()-fail on: struct S { const int& x = 7; }; in C++ mode. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D94804 Files: clang/lib/AST/DeclBase.cpp clang/test/PCH/cxx-reference.h Index: clang/test/PCH/cxx-reference.h =================================================================== --- clang/test/PCH/cxx-reference.h +++ clang/test/PCH/cxx-reference.h @@ -11,3 +11,7 @@ LR &&rrlr = c; RR &lrrr = c; RR &&rrrr = 'c'; + +struct S { + const int &x = 1; // LifetimeExtendedTemporary inside struct +}; Index: clang/lib/AST/DeclBase.cpp =================================================================== --- clang/lib/AST/DeclBase.cpp +++ clang/lib/AST/DeclBase.cpp @@ -971,21 +971,19 @@ // 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 &&
Index: clang/test/PCH/cxx-reference.h =================================================================== --- clang/test/PCH/cxx-reference.h +++ clang/test/PCH/cxx-reference.h @@ -11,3 +11,7 @@ LR &&rrlr = c; RR &lrrr = c; RR &&rrrr = 'c'; + +struct S { + const int &x = 1; // LifetimeExtendedTemporary inside struct +}; Index: clang/lib/AST/DeclBase.cpp =================================================================== --- clang/lib/AST/DeclBase.cpp +++ clang/lib/AST/DeclBase.cpp @@ -971,21 +971,19 @@ // 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 &&
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits