diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-05-06 03:47:15 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-05-06 03:47:15 +0000 |
| commit | b9fb121a62de69686dc193d32cba680a1a645277 (patch) | |
| tree | 5ae91995df8eb4264fd2fa71fe3ef48a8e95d160 /clang/test/SemaCXX/new-delete.cpp | |
| parent | 9dd6537b3acf98c942cdb020c6ea26d9af309eb3 (diff) | |
| download | bcm5719-llvm-b9fb121a62de69686dc193d32cba680a1a645277.tar.gz bcm5719-llvm-b9fb121a62de69686dc193d32cba680a1a645277.zip | |
[c++20] Implement P1009R2: allow omitting the array bound in an array
new expression.
This was voted into C++20 as a defect report resolution, so we
retroactively apply it to all prior language modes (though it can never
actually be used before C++11 mode).
llvm-svn: 360006
Diffstat (limited to 'clang/test/SemaCXX/new-delete.cpp')
| -rw-r--r-- | clang/test/SemaCXX/new-delete.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/clang/test/SemaCXX/new-delete.cpp b/clang/test/SemaCXX/new-delete.cpp index 870a5921d25..4db1206b6c0 100644 --- a/clang/test/SemaCXX/new-delete.cpp +++ b/clang/test/SemaCXX/new-delete.cpp @@ -65,6 +65,12 @@ void good_news() typedef foo x[2]; typedef foo y[2][2]; x* f3 = new y; + +#if __cplusplus >= 201103L + (void)new int[]{}; + (void)new int[]{1, 2, 3}; + (void)new char[]{"hello"}; +#endif } struct abstract { @@ -126,9 +132,14 @@ void bad_news(int *ip) (void)::new ((S*)0) U; // expected-error {{no matching function for call to 'operator new'}} // This must fail, because any member version hides all global versions. (void)new U; // expected-error {{no matching function for call to 'operator new'}} - (void)new (int[]); // expected-error {{array size must be specified in new expressions}} + (void)new (int[]); // expected-error {{array size must be specified in new expression with no initializer}} (void)new int&; // expected-error {{cannot allocate reference type 'int &' with new}} - // Some lacking cases due to lack of sema support. + (void)new int[]; // expected-error {{array size must be specified in new expression with no initializer}} + (void)new int[](); // expected-error {{cannot determine allocated array size from initializer}} + // FIXME: This is a terrible diagnostic. +#if __cplusplus < 201103L + (void)new int[]{}; // expected-error {{array size must be specified in new expression with no initializer}} +#endif } void good_deletes() @@ -601,3 +612,12 @@ struct A { void g() { this->::delete; } // expected-error {{expected unqualified-id}} }; } + +#if __cplusplus >= 201103L +template<typename ...T> int *dependent_array_size(T ...v) { + return new int[]{v...}; // expected-error {{cannot initialize}} +} +int *p0 = dependent_array_size(); +int *p3 = dependent_array_size(1, 2, 3); +int *fail = dependent_array_size("hello"); // expected-note {{instantiation of}} +#endif |

