@@ -166,23 +166,41 @@ void f1() {
166166 short a;
167167 };
168168
169- // on some systems, placement array new may allocate more memory than the nominal size of the array
170- // in such cases, test code could be problematic, but the checker doesn't warn here because this behavior is expected to be rare
169+ // On some systems, (notably before MSVC 16.7), a non-allocating placement
170+ // array new could allocate more memory than the nominal size of the array.
171+
172+ // Since CWG 2382 (implemented in MSVC 16.7), overhead was disallowed for non-allocating placement new.
173+ // See:
174+ // https://learn.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance?view=msvc-170
175+ // https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1969r0.html#2382
176+
177+ // However, as of 17.1, there is a regression when the type comes from a template
178+ // parameter where MSVC reintroduces overhead.
179+ // See:
180+ // https://developercommunity.visualstudio.com/t/10777485
181+ // https://godbolt.org/z/E1z1Tsfvj
182+
183+ // The checker doesn't warn here because this behavior only affects older
184+ // MSVC versions (<16.7) or certain specific versions (17.1).
185+ // Suppressing warnings avoids false positives on standard-compliant compilers
186+ // and modern MSVC versions, but users of affected MSVC versions should be
187+ // aware of potential buffer size issues.
188+
171189 const unsigned N = 32 ;
172190 alignas (S) unsigned char buffer1[sizeof (S) * N];
173- ::new (buffer1) S[N];
191+ ::new (buffer1) S[N]; // no-warning: See comments above
174192}
175193
176194void f2 () {
177195 struct S {
178196 short a;
179197 };
180198
181- // on some systems, placement array new may allocate more memory than the nominal size of the array
182- // in such cases, test code could be problematic, but the checker doesn't warn here because this behavior is expected to be rare
199+ // On some systems, placement array new could allocate more memory than the nominal size of the array.
200+ // See the comment at f1() above for more details.
183201 const unsigned N = 32 ;
184202 alignas (S) unsigned char buffer2[sizeof (S) * N + sizeof (int )];
185- ::new (buffer2) S[N];
203+ ::new (buffer2) S[N]; // no-warning: See comments above
186204}
187205} // namespace testArrayTypesAllocation
188206
0 commit comments