[PATCH] D122935: [AST] Dont invalidate a ref-type var decl if it has no initializer.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 1 12:52:47 PDT 2022


hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang.

This would allow more AST nodes being preserved for broken code, and
have a more consistent valid bit for ref-type var decl (currently, a
ref-type var decl with a broken initializer is valid).

Per https://reviews.llvm.org/D76831#1973053, the initializer of a variable
should play no part in its "invalid" bit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122935

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/AST/ast-dump-invalid-initialized.cpp


Index: clang/test/AST/ast-dump-invalid-initialized.cpp
===================================================================
--- clang/test/AST/ast-dump-invalid-initialized.cpp
+++ clang/test/AST/ast-dump-invalid-initialized.cpp
@@ -12,10 +12,10 @@
   const A a2;
   // CHECK: `-VarDecl {{.*}} a3 'A'
   A a3 = garbage();
+  // CHECK: `-VarDecl {{.*}} a4 'const A &'
+  const A& a4;
 
 
-  // CHECK: `-VarDecl {{.*}} invalid b1 'const A &'
-  const A& b1;
   // CHECK: `-VarDecl {{.*}} invalid b2 'ForwardDecl'
   ForwardDecl b2;
   // CHECK: `-VarDecl {{.*}} invalid b3 'auto'
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13006,7 +13006,6 @@
     if (Type->isReferenceType()) {
       Diag(Var->getLocation(), diag::err_reference_var_requires_init)
           << Var << SourceRange(Var->getLocation(), Var->getLocation());
-      Var->setInvalidDecl();
       return;
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122935.419839.patch
Type: text/x-patch
Size: 1002 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220401/6b364479/attachment.bin>


More information about the cfe-commits mailing list