Crash on invalid on NVRO within template instantiation #51050
Labels
bugzilla
Issues migrated from bugzilla
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
Extended Description
This crash was first observed at this revision:
f2d5fce
As seen in the test case below, the crash happens when the VarDecl being tested for NVRO is invalid during template instantiation.
Testing shows that in TemplateDeclInstantiator::VisitVarDecl, if the call to SemaRef.getNamedReturnInfo is skipped when Var->isInvalidDecl(), then the crash can be avoided. Although a better fix would be to handle invalid Decl's when checking alignment.
$ cat test.ii
template
class a
;
template
b f() {
b d;
return d;
}
auto e = {
f< a< int > >() };
$ clang test.ii
test.ii:10:3: error: implicit instantiation of undefined template 'a'
f< a< int > >() };
^
test.ii:2:7: note: template is declared here
class a
^
test.ii:5:3: error: implicit instantiation of undefined template 'a'
b f() {
^
test.ii:10:3: note: in instantiation of function template specialization 'f<a>' requested here
f< a< int > >() };
^
test.ii:2:7: note: template is declared here
class a
^
test.ii:6:5: error: implicit instantiation of undefined template 'a'
b d;
^
test.ii:2:7: note: template is declared here
class a
^
clang/lib/AST/RecordLayoutBuilder.cpp:3256: const clang::ASTRecordLayout &clang::ASTContext::getASTRecordLayout(const clang::RecordDecl *) const: Assertion `D && "Cannot get layout of forward declarations!"' failed.
The text was updated successfully, but these errors were encountered: