Skip to content

Commit

Permalink
[AST] Dont invalidate a ref-type var decl if it has no initializer.
Browse files Browse the repository at this point in the history
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.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D122935
  • Loading branch information
hokein committed May 25, 2022
1 parent 788463e commit c673d67
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
1 change: 0 additions & 1 deletion clang/lib/Sema/SemaDecl.cpp
Expand Up @@ -13199,7 +13199,6 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl) {
if (Type->isReferenceType()) {
Diag(Var->getLocation(), diag::err_reference_var_requires_init)
<< Var << SourceRange(Var->getLocation(), Var->getLocation());
Var->setInvalidDecl();
return;
}

Expand Down
4 changes: 2 additions & 2 deletions clang/test/AST/ast-dump-invalid-initialized.cpp
Expand Up @@ -12,10 +12,10 @@ void test() {
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'
Expand Down

0 comments on commit c673d67

Please sign in to comment.