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

Adam Czachorowski via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 18 10:29:57 PST 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG196cc96f9a64: [clang] Allow LifetimeExtendedTemporary to have no access specifier (authored by adamcz).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94804/new/

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.317389.patch
Type: text/x-patch
Size: 1751 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210118/919008ba/attachment.bin>


More information about the cfe-commits mailing list