Skip to content

Commit 91836b9

Browse files
committed
Diagnose reflections of lambda captures.
1 parent f4cb62e commit 91836b9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3152,6 +3152,8 @@ def err_reflect_overload_set : Error<
31523152
"cannot take the reflection of an overload set">;
31533153
def err_reflect_nttp : Error<
31543154
"cannot take the reflection of a non-type template parameter">;
3155+
def err_reflect_init_capture : Error<
3156+
"cannot take the reflection of a captured local entity">;
31553157
def err_template_arg_bad_reflection_kind : Error<
31563158
"reflection of this kind cannot appear as a template argument">;
31573159
def err_reflect_dependent_splice : Error<

clang/lib/Sema/SemaReflect.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,8 @@ ExprResult Sema::ActOnCXXReflectExpr(SourceLocation OpLoc,
785785
if (Found.isAmbiguous()) {
786786
return ExprError();
787787
} else if (Found.isOverloadedResult() && Found.end() - Found.begin() > 1) {
788-
Diag(Id.StartLocation, diag::err_reflect_overload_set);
788+
Diag(Id.StartLocation, diag::err_reflect_overload_set)
789+
<< Id.getSourceRange();
789790
return ExprError();
790791
}
791792

@@ -814,6 +815,15 @@ ExprResult Sema::ActOnCXXReflectExpr(SourceLocation OpLoc,
814815
if (isa<NamespaceDecl, NamespaceAliasDecl, TranslationUnitDecl>(ND))
815816
return BuildCXXReflectExpr(OpLoc, NameInfo.getBeginLoc(), ND);
816817

818+
if (auto *VD = dyn_cast<VarDecl>(ND);
819+
VD && (VD->isInitCapture() ||
820+
NeedToCaptureVariable(VD, Id.StartLocation))) {
821+
Diag(Id.StartLocation, diag::err_reflect_init_capture)
822+
<< Id.getSourceRange();
823+
return ExprError();
824+
}
825+
826+
817827
// Why do we have to build an expression here? Just stash in an APValue?
818828
if (isa<VarDecl, BindingDecl, FunctionDecl, FieldDecl, EnumConstantDecl,
819829
NonTypeTemplateParmDecl>(ND)) {

0 commit comments

Comments
 (0)