Entity proxies are ill-formed in P2996.

This commit is contained in:
Dan Katz
2025-06-11 11:28:41 -04:00
parent b5a6e6d1f2
commit 27564fbd5d
4 changed files with 17 additions and 10 deletions

View File

@@ -3136,6 +3136,8 @@ def err_reflect_overload_set : Error<
"cannot take the reflection of an overload set">;
def err_reflect_nttp : Error<
"cannot take the reflection of a non-type template parameter">;
def err_reflect_using_declarator : Error<
"cannot take the reflection of a using-declarator">;
def err_reflect_init_capture : Error<
"cannot take the reflection of a local entity declared by init-capture">;
def err_reflect_local_requires_param : Error<

View File

@@ -7196,7 +7196,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-freflection");
CmdArgs.push_back("-fparameter-reflection");
CmdArgs.push_back("-fannotation-attributes");
CmdArgs.push_back("-fentity-proxy-reflection");
CmdArgs.push_back("-fexpansion-statements");
}

View File

@@ -893,9 +893,10 @@ ExprResult Sema::ActOnCXXReflectExpr(SourceLocation OpLoc,
if (auto *USD = dyn_cast<UsingShadowDecl>(ND)) {
if (getLangOpts().EntityProxyReflection)
return BuildCXXReflectExpr(OpLoc, NameInfo.getBeginLoc(), USD);
else do
ND = cast<UsingShadowDecl>(ND)->getTargetDecl();
while (isa<UsingShadowDecl>(ND));
else {
Diag(SS.getBeginLoc(), diag::err_reflect_using_declarator);
return ExprError();
}
}
if (auto *TD = dyn_cast<TypeDecl>(ND)) {
@@ -1134,8 +1135,10 @@ ExprResult Sema::BuildCXXReflectExpr(SourceLocation OperatorLoc,
if (auto *UT = dyn_cast<UsingType>(T)) {
if (Context.getLangOpts().EntityProxyReflection)
return BuildCXXReflectExpr(OperatorLoc, OperandLoc, UT->getFoundDecl());
else
T = UT->getUnderlyingType();
else {
Diag(OperandLoc, diag::err_reflect_using_declarator);
return ExprError();
}
}
if (auto *STTPTy = T->getAs<SubstTemplateTypeParmType>())
@@ -1163,12 +1166,15 @@ ExprResult Sema::BuildCXXReflectExpr(SourceLocation OperatorLoc,
ReflectionKind RK = ReflectionKind::Declaration;
if (isa<TranslationUnitDecl, NamespaceDecl, NamespaceAliasDecl>(D))
RK = ReflectionKind::Namespace;
else if (isa<UsingShadowDecl>(D))
else if (isa<UsingShadowDecl>(D)) {
if (!getLangOpts().EntityProxyReflection) {
Diag(OperandLoc, diag::err_reflect_using_declarator);
return ExprError();
}
RK = ReflectionKind::EntityProxy;
}
APValue RV(RK, D);
if (!getLangOpts().EntityProxyReflection)
RV = MaybeUnproxy(Context, RV);
return CXXReflectExpr::Create(Context, OperatorLoc,
SourceRange(OperandLoc, OperandLoc), RV);
}

View File

@@ -8,7 +8,7 @@
//
//===----------------------------------------------------------------------===//
//
// RUN: %clang_cc1 %s -std=c++23 -freflection
// RUN: %clang_cc1 %s -std=c++23 -freflection -fentity-proxy-reflection
using info = decltype(^^int);