@@ -12,10 +12,9 @@ static_assert(alloc_from_user_code()); // expected-error {{constant expression}}
12
12
13
13
namespace std {
14
14
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
16
15
template <typename T> struct allocator {
17
16
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);
19
18
}
20
19
constexpr void deallocate (void *p) {
21
20
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) {
59
58
p = new int [1 ]; // expected-note {{heap allocation}}
60
59
break ;
61
60
case 2 :
62
- p = std::allocator<int >().allocate (1 );
61
+ p = std::allocator<int >().allocate (1 ); // expected-note 2{{heap allocation}}
63
62
break ;
64
63
}
65
64
switch (dealloc_kind) {
@@ -81,8 +80,10 @@ static_assert(mismatched(2, 0)); // expected-error {{constant expression}} expec
81
80
static_assert (mismatched(2 , 1 )); // expected-error {{constant expression}} expected-note {{in call}}
82
81
static_assert (mismatched(2 , 2 ));
83
82
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}}
86
87
constexpr int no_lifetime_start = (*std::allocator<int >().allocate(1 ) = 1 ); // expected-error {{constant expression}} expected-note {{assignment to object outside its lifetime}}
87
88
constexpr int no_deallocate_nullptr = (std::allocator<int >().deallocate(nullptr ), 1 ); // expected-error {{constant expression}} expected-note {{in call}}
88
89
// expected-note@#dealloc {{'std::allocator<...>::deallocate' used to delete a null pointer}}
0 commit comments