[PATCH] D100713: [clang] NFC: refactor usage of getDecltypeForParenthesizedExpr
Matheus Izvekov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri May 14 14:38:11 PDT 2021
mizvekov added a comment.
In D100713#2759637 <https://reviews.llvm.org/D100713#2759637>, @aaronpuchert wrote:
> Again, I'm not sure if it helps to use `getDecltypeForParenthesizedExpr` where we don't actually have the `decltype` of a parenthesized expression.
>
> It's probably not entirely coincidental, but things aren't defined this way.
The current situation with `getDecltypeForParenthesizedExpr` is that it already is used in some places where there is no decltype of a parenthesized expression either.
This function is a bit new, I introduced it in D98160 <https://reviews.llvm.org/D98160>. I think the mnemonic is OK, but this is the best I could come up at the time. If you have better suggestions, I am all for it.
In the above patch, this is introduced to help out with the type for the expression in a compound requires (http://eel.is/c++draft/expr.prim.req.compound#1.3.2).
But then it is also used in the implementation of decltype itself, where it kicks in even for non-parenthesized expressions (if the expression is not otherwise a special case, as defined in https://eel.is/c++draft/dcl.type.decltype#1).
I think the standard just missed giving a name to this pattern, and it otherwise IMHO misses the mark by using something more complex to explain something simpler.
I think it's no coincidence that for the patch I am working on, I had to change all of these copies in exactly the same way :)
================
Comment at: clang/lib/Sema/SemaExprCXX.cpp:5845
+ if (!To->isRValue()) {
+ QualType T = Self.Context.getDecltypeForParenthesizedExpr(To);
InitializedEntity Entity = InitializedEntity::InitializeTemporary(T);
----------------
aaronpuchert wrote:
> mizvekov wrote:
> > aaronpuchert wrote:
> > > The quote doesn't reference parenthesized expressions, isn't this just coincidentally the same thing?
> > It's fundamentally the same thing. The `getDecltypeForParenthesizedExpr` name is what I tried to keep, I don't have better ideas there.
> What this is doing is pointwise equal to `getDecltypeForParenthesizedExpr`, but there is no parenthesized expression, and no `decltype`. There is a quote from the standard that defines this separately (by now this seems to be [[http://eel.is/c++draft/expr.cond#4|expr.cond#4]]), and there are some differences especially in the prvalue case. So I'm not sure this helps.
Here for XValue and and LValue, the rules are exactly the same as https://eel.is/c++draft/dcl.type.decltype#1.
And the original code here even already special cases it...
I am sure there is some way we can agree that we should not repeat the code just because the standard did not bother to give a name to this part of the rules... And again I think it is no coincidence that it makes sense to perform the same changes in all these cases.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D100713/new/
https://reviews.llvm.org/D100713
More information about the cfe-commits
mailing list