Skip to content

Latest commit

 

History

History
20 lines (16 loc) · 936 Bytes

compiler-error-c2076.md

File metadata and controls

20 lines (16 loc) · 936 Bytes
description title ms.date f1_keywords helpviewer_keywords
Learn more about: Compiler Error C2076
Compiler Error C2076
08/18/2022
C2076
C2076

Compiler Error C2076

a brace-enclosed initializer list cannot be used in a new-expression whose type contains 'auto/decltype(auto)'

If an auto type-specifier appears in the specifier sequence of a new type-identifier or the type-identifier of a new expression, the expression must contain an initializer of the form ( assignment-expression ). The compiler deduces the type-identifier from the assignment-expression in the initializer. For example,

new auto(42);            // new allocates int
auto c = new auto('a');  // c is of type char*, new allocates char
new (auto*)(static_cast<short*>(nullptr));   // allocates type short*

To resolve this issue, use parentheses to enclose the initialization value of the new expression.