[clang] [clang] disallow narrowing when matching template template parameters (PR #124313)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 24 12:46:22 PST 2025
================
@@ -6930,17 +6934,20 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
IsConvertedConstantExpression = false;
}
- if (getLangOpts().CPlusPlus17) {
+ if (getLangOpts().CPlusPlus17 || PartialOrderingTTP) {
// C++17 [temp.arg.nontype]p1:
// A template-argument for a non-type template parameter shall be
// a converted constant expression of the type of the template-parameter.
APValue Value;
ExprResult ArgResult;
if (IsConvertedConstantExpression) {
- ArgResult = BuildConvertedConstantExpression(Arg, ParamType,
- CCEK_TemplateArg, Param);
- if (ArgResult.isInvalid())
+ ArgResult = BuildConvertedConstantExpression(
+ Arg, ParamType,
+ PartialOrderingTTP ? CCEK_InjectedTTP : CCEK_TemplateArg, Param);
+ if (ArgResult.isInvalid()) {
----------------
erichkeane wrote:
ExprResult always being initialized isn't a bad idea... but a much bigger change than i'd request here. That said, the `Build/Act` functions SOMETIMES return uninit (even if by accident sometimes, particularly when used as an out param). So the `isUsable` is both what we typically mean, and the safer option.
I realize we are bad about `isInvalid` all over the place, I've actively been trying to stop using it as we never MEAN it, so I show a strict preference for `isUsable`, particularly in these cases. IMO, `isInvalid` becoming deprecated is perhaps of value.
https://github.com/llvm/llvm-project/pull/124313
More information about the cfe-commits
mailing list