Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 0e1da5f

Browse files
committed
PR31742: Don't emit a bogus "zero size array" extwarn when initializing a
runtime-sized array from an empty list in an array new. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@292991 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent eeb00e3 commit 0e1da5f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Diff for: lib/Sema/SemaInit.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,7 @@ void InitListChecker::CheckArrayType(const InitializedEntity &Entity,
16841684
// If this is an incomplete array type, the actual type needs to
16851685
// be calculated here.
16861686
llvm::APSInt Zero(maxElements.getBitWidth(), maxElements.isUnsigned());
1687-
if (maxElements == Zero) {
1687+
if (maxElements == Zero && !Entity.isVariableLengthArrayNew()) {
16881688
// Sizing an array implicitly to zero is not allowed by ISO C,
16891689
// but is supported by GNU.
16901690
SemaRef.Diag(IList->getLocStart(),

Diff for: test/SemaCXX/new-delete-cxx0x.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -triple=i686-pc-linux-gnu
1+
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -triple=i686-pc-linux-gnu -pedantic
22

33
void ugly_news(int *ip) {
44
(void)new int[-1]; // expected-error {{array size is negative}}
@@ -29,6 +29,7 @@ void fn(int n) {
2929
(void) new int[2] {1, 2};
3030
(void) new S[2] {1, 2};
3131
(void) new S[3] {1, 2};
32+
(void) new S[n] {};
3233
// C++11 [expr.new]p19:
3334
// If the new-expression creates an object or an array of objects of class
3435
// type, access and ambiguity control are done for the allocation function,
@@ -44,6 +45,7 @@ void fn(int n) {
4445
(void) new T[2] {1, 2}; // ok
4546
(void) new T[3] {1, 2}; // expected-error {{no matching constructor}} expected-note {{in implicit initialization of array element 2}}
4647
(void) new T[n] {1, 2}; // expected-error {{no matching constructor}} expected-note {{in implicit initialization of trailing array elements in runtime-sized array new}}
48+
(void) new T[n] {}; // expected-error {{no matching constructor}} expected-note {{in implicit initialization of trailing array elements in runtime-sized array new}}
4749
}
4850

4951
struct U {

0 commit comments

Comments
 (0)