summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2017-01-24 23:18:28 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2017-01-24 23:18:28 +0000
commit73edb6d0ccb0924907ce612e731db31b2a8399b1 (patch)
treecdb1fbc3c303785c358d2586e4298abe8d8e2463 /clang
parent63b560be69c0660b427efe903689f410e1f02967 (diff)
downloadbcm5719-llvm-73edb6d0ccb0924907ce612e731db31b2a8399b1.tar.gz
bcm5719-llvm-73edb6d0ccb0924907ce612e731db31b2a8399b1.zip
PR31742: Don't emit a bogus "zero size array" extwarn when initializing a
runtime-sized array from an empty list in an array new. llvm-svn: 292991
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Sema/SemaInit.cpp2
-rw-r--r--clang/test/SemaCXX/new-delete-cxx0x.cpp4
2 files changed, 4 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index c385689d4c3..aae08a9132f 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -1684,7 +1684,7 @@ void InitListChecker::CheckArrayType(const InitializedEntity &Entity,
// If this is an incomplete array type, the actual type needs to
// be calculated here.
llvm::APSInt Zero(maxElements.getBitWidth(), maxElements.isUnsigned());
- if (maxElements == Zero) {
+ if (maxElements == Zero && !Entity.isVariableLengthArrayNew()) {
// Sizing an array implicitly to zero is not allowed by ISO C,
// but is supported by GNU.
SemaRef.Diag(IList->getLocStart(),
diff --git a/clang/test/SemaCXX/new-delete-cxx0x.cpp b/clang/test/SemaCXX/new-delete-cxx0x.cpp
index c55152510e1..4ef586f2e56 100644
--- a/clang/test/SemaCXX/new-delete-cxx0x.cpp
+++ b/clang/test/SemaCXX/new-delete-cxx0x.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -triple=i686-pc-linux-gnu
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -triple=i686-pc-linux-gnu -pedantic
void ugly_news(int *ip) {
(void)new int[-1]; // expected-error {{array size is negative}}
@@ -29,6 +29,7 @@ void fn(int n) {
(void) new int[2] {1, 2};
(void) new S[2] {1, 2};
(void) new S[3] {1, 2};
+ (void) new S[n] {};
// C++11 [expr.new]p19:
// If the new-expression creates an object or an array of objects of class
// type, access and ambiguity control are done for the allocation function,
@@ -44,6 +45,7 @@ void fn(int n) {
(void) new T[2] {1, 2}; // ok
(void) new T[3] {1, 2}; // expected-error {{no matching constructor}} expected-note {{in implicit initialization of array element 2}}
(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}}
+ (void) new T[n] {}; // expected-error {{no matching constructor}} expected-note {{in implicit initialization of trailing array elements in runtime-sized array new}}
}
struct U {
OpenPOWER on IntegriCloud