[PATCH] D158615: [clang] Emit an error if variable ends up with incomplete array type
Mariya Podchishchaeva via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 29 02:28:16 PDT 2023
Fznamznon updated this revision to Diff 554220.
Fznamznon added a comment.
Apply suggestion, rebase to maybe pass precommit
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D158615/new/
https://reviews.llvm.org/D158615
Files:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/gh37257.cpp
Index: clang/test/SemaCXX/gh37257.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/gh37257.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template<class T>
+T&& create();
+
+template<class T, class... Args>
+void test() {
+ T t(create<Args>()...); // expected-error{{variable has incomplete type 'int[]'}}
+ (void) t;
+}
+
+struct A;
+
+int main() {
+ test<int[]>(); // expected-note {{in instantiation of function template specialization 'test<int[]>' requested here}}
+}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13445,6 +13445,18 @@
IsParenListInit = !InitSeq.steps().empty() &&
InitSeq.step_begin()->Kind ==
InitializationSequence::SK_ParenthesizedListInit;
+ QualType VDeclType = VDecl->getType();
+ if (Init && !Init->getType().isNull() &&
+ !Init->getType()->isDependentType() && !VDeclType->isDependentType() &&
+ Context.getAsIncompleteArrayType(VDeclType) &&
+ Context.getAsIncompleteArrayType(Init->getType())) {
+ // Bail out if it is not possible to deduce array size from the
+ // initializer.
+ Diag(VDecl->getLocation(), diag::err_typecheck_decl_incomplete_type)
+ << VDeclType;
+ VDecl->setInvalidDecl();
+ return;
+ }
}
// Check for self-references within variable initializers.
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -193,6 +193,9 @@
(`#64876 <https://github.com/llvm/llvm-project/issues/64876>`_)
- Fixed an assertion if a function has cleanups and fatal erors.
(`#48974 <https://github.com/llvm/llvm-project/issues/48974>`_)
+- Clang now emits an error if it is not possible to deduce array size for a
+ variable with incomplete array type.
+ (`#37257 <https://github.com/llvm/llvm-project/issues/37257>`_)
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158615.554220.patch
Type: text/x-patch
Size: 2175 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230829/3de443a5/attachment.bin>
More information about the cfe-commits
mailing list