[PATCH] D94804: [clang] Allow LifetimeExtendedTemporary to have no access specifier

Adam Czachorowski via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 15 09:42:55 PST 2021


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 &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94804.317004.patch
Type: text/x-patch
Size: 1751 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210115/278836b3/attachment-0001.bin>


More information about the cfe-commits mailing list