Clang error: cannot deduce type for lambda capture B from ... initializer list (err_init_capture_paren_braces)
Jump to navigation
Jump to search
Text |
| ||||||
---|---|---|---|---|---|---|---|
Type | Error | ||||||
Category | Lambda Issue | ||||||
Internal Id | err_init_capture_paren_braces | ||||||
Internal Message | cannot deduce type for lambda capture %1 from %select{parenthesized|nested}0 initializer list
| ||||||
Regular Expression | (?:error|fatal error)\: cannot deduce type for lambda capture (.*?) from (?:parenthesized|nested) initializer list
| ||||||
First Commit | 2014-03-12 66204ecff985 DR1346: a parenthesized braced-init-list cannot be used as the initializer when |
Description
Example
Flags | -xc++
|
|
---|---|---|
Source |
int main() {
// Cannot deduce type for lambda capture from initializer list
auto l = [x({1, 2})](){};
}
| |
Compiler Output |
<source>:3:14: error: cannot deduce type for lambda capture 'x' from parenthesized initializer list |
Clang Internals (17.0.6)
Git Commit Message
DR1346: a parenthesized braced-init-list cannot be used as the initializer when performing auto type deduction. llvm-svn: 203683
Used in Clang Sources
This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.
clang/lib/Sema/SemaDecl.cpp (line 12747)
QualType Sema::deduceVarTypeFromInitializer(VarDecl *VDecl, DeclarationName Name, QualType Type, TypeSourceInfo *TSI, SourceRange Range, bool DirectInit, Expr *Init) {
// ...
if (DirectInit && isa<InitListExpr>(DeduceInit)) {
Diag(Init->getBeginLoc(), IsInitCapture ? diag::err_init_capture_paren_braces : diag::err_auto_var_init_paren_braces) << isa<InitListExpr>(Init) << VN << Type << Range;
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp
- clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp:53:21: error: cannot deduce type for lambda capture 'a' from nested initializer list