@@ -12,10 +12,9 @@ static_assert(alloc_from_user_code()); // expected-error {{constant expression}}
1212
1313namespace std {
1414 using size_t = decltype (sizeof (0 ));
15- // FIXME: It would be preferable to point these notes at the location of the call to allocator<...>::[de]allocate instead
1615 template <typename T> struct allocator {
1716 constexpr T *allocate (size_t N) {
18- return (T*)NEW (sizeof (T) * N); // expected-note 3{{heap allocation}} expected-note {{not deallocated}}
17+ return (T*)NEW (sizeof (T) * N);
1918 }
2019 constexpr void deallocate (void *p) {
2120 DELETE (p); // #dealloc expected-note 2{{'std::allocator<...>::deallocate' used to delete pointer to object allocated with 'new'}}
@@ -59,7 +58,7 @@ constexpr bool mismatched(int alloc_kind, int dealloc_kind) {
5958 p = new int [1 ]; // expected-note {{heap allocation}}
6059 break ;
6160 case 2 :
62- p = std::allocator<int >().allocate (1 );
61+ p = std::allocator<int >().allocate (1 ); // expected-note 2{{heap allocation}}
6362 break ;
6463 }
6564 switch (dealloc_kind) {
@@ -81,8 +80,10 @@ static_assert(mismatched(2, 0)); // expected-error {{constant expression}} expec
8180static_assert (mismatched(2 , 1 )); // expected-error {{constant expression}} expected-note {{in call}}
8281static_assert (mismatched(2 , 2 ));
8382
84- constexpr int *escape = std::allocator<int >().allocate(3 ); // expected-error {{constant expression}} expected-note {{pointer to subobject of heap-allocated}}
85- constexpr int leak = (std::allocator<int >().allocate(3 ), 0 ); // expected-error {{constant expression}}
83+ constexpr int *escape = std::allocator<int >().allocate(3 ); // expected-error {{constant expression}} expected-note {{pointer to subobject of heap-allocated}} \
84+ // expected-note {{heap allocation performed here}}
85+ constexpr int leak = (std::allocator<int >().allocate(3 ), 0 ); // expected-error {{constant expression}} \
86+ // expected-note {{not deallocated}}
8687constexpr int no_lifetime_start = (*std::allocator<int >().allocate(1 ) = 1 ); // expected-error {{constant expression}} expected-note {{assignment to object outside its lifetime}}
8788constexpr int no_deallocate_nullptr = (std::allocator<int >().deallocate(nullptr ), 1 ); // expected-error {{constant expression}} expected-note {{in call}}
8889// expected-note@#dealloc {{'std::allocator<...>::deallocate' used to delete a null pointer}}
0 commit comments