adamcz updated this revision to Diff 416561. adamcz added a comment. changed to marking VarDecl as invalid if it's ref type and initializer is invalid
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D121824/new/ https://reviews.llvm.org/D121824 Files: clang/lib/Sema/SemaDecl.cpp clang/test/AST/ast-dump-invalid-initialized.cpp clang/test/SemaCXX/arrow-operator.cpp Index: clang/test/SemaCXX/arrow-operator.cpp =================================================================== --- clang/test/SemaCXX/arrow-operator.cpp +++ clang/test/SemaCXX/arrow-operator.cpp @@ -65,3 +65,24 @@ } } // namespace arrow_suggest + +namespace no_crash_dependent_type { + +template<class T> +struct A { + void call(); + A* operator->(); +}; + +template <class T> +void foo() { + // x is dependent. + A<int>& x = blah[7]; // expected-error {{use of undeclared identifier 'blah'}} + x->call(); +} + +void test() { + foo<int>(); +} + +} // namespace no_crash_dependent_type 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 @@ -24,4 +24,6 @@ auto b4 = A(1); // CHECK: `-VarDecl {{.*}} invalid b5 'auto' auto b5 = A{1}; -} \ No newline at end of file + // CHECK: `-VarDecl {{.*}} invalid b6 'A &' + A& b6 = garbage[1]; +} Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -12794,6 +12794,12 @@ return; } + // Reference type without initializer doesn't work. + if (VD->getType()->isReferenceType()) { + VD->setInvalidDecl(); + return; + } + QualType Ty = VD->getType(); if (Ty->isDependentType()) return;
Index: clang/test/SemaCXX/arrow-operator.cpp =================================================================== --- clang/test/SemaCXX/arrow-operator.cpp +++ clang/test/SemaCXX/arrow-operator.cpp @@ -65,3 +65,24 @@ } } // namespace arrow_suggest + +namespace no_crash_dependent_type { + +template<class T> +struct A { + void call(); + A* operator->(); +}; + +template <class T> +void foo() { + // x is dependent. + A<int>& x = blah[7]; // expected-error {{use of undeclared identifier 'blah'}} + x->call(); +} + +void test() { + foo<int>(); +} + +} // namespace no_crash_dependent_type 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 @@ -24,4 +24,6 @@ auto b4 = A(1); // CHECK: `-VarDecl {{.*}} invalid b5 'auto' auto b5 = A{1}; -} \ No newline at end of file + // CHECK: `-VarDecl {{.*}} invalid b6 'A &' + A& b6 = garbage[1]; +} Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -12794,6 +12794,12 @@ return; } + // Reference type without initializer doesn't work. + if (VD->getType()->isReferenceType()) { + VD->setInvalidDecl(); + return; + } + QualType Ty = VD->getType(); if (Ty->isDependentType()) return;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits