Skip to content

Commit 82d2561

Browse files
committed
[Clang][Sema] Fix crash when type used in return statement contains errors
In Sema in `BuildReturnStmt(...)` when we try to determine is the type is move eligable or copy elidable we don't currently check of the init of the `VarDecl` contain errors or not. This can lead to a crash since we may send a type that is not complete into `getTypeInfo(...)` which does not allow this. This fixes: #63244 #79745
1 parent 4eeeeb3 commit 82d2561

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

clang/lib/Sema/SemaStmt.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3391,6 +3391,8 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(Expr *&E,
33913391
const auto *VD = dyn_cast<VarDecl>(DR->getDecl());
33923392
if (!VD)
33933393
return NamedReturnInfo();
3394+
if (VD->getInit() && VD->getInit()->containsErrors())
3395+
return NamedReturnInfo();
33943396
NamedReturnInfo Res = getNamedReturnInfo(VD);
33953397
if (Res.Candidate && !E->isXValue() &&
33963398
(Mode == SimplerImplicitMoveMode::ForceOn ||

clang/test/SemaCXX/deduced-return-type-cxx14.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,3 +724,12 @@ struct DeducedTargetTypeOfConversionFunction {
724724
// since-cxx20-error@-1 {{'decltype(auto)' not allowed in declaration of conversion function template}}
725725
#endif
726726
};
727+
728+
namespace GH79745 {
729+
template <typename = int> struct a; // expected-note {{template is declared here}}
730+
auto f() {
731+
a c; // cxx20_23-error {{implicit instantiation of undefined template}} \
732+
// cxx14-error {{use of class template 'a' requires template arguments}}
733+
return c;
734+
}
735+
}

0 commit comments

Comments
 (0)