[llvm-dev] BinaryOperator vs. CXXOperatorCallExpr in template code
Richard Smith via llvm-dev
llvm-dev at lists.llvm.org
Tue Jun 15 17:00:27 PDT 2021
On Wed, 9 Jun 2021 at 23:18, Stephan Bergmann via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> I now see that I had accidentally sent the below to llvm-dev rather than
> cfe-dev. (Also, see the comments at
> <https://reviews.llvm.org/D103949#2808256> "Only consider built-in
> compound assignment operators for -Wunused-but-set-*" for the place
> where this questions came up.)
>
> On 04/06/2021 09:54, Stephan Bergmann wrote:
> > Ever since
> > <
> https://github.com/llvm/llvm-project/commit/d2b7ef6ecea967b70bdeb8a1fd8004c5aef3e415>
>
> > "Improve the representation of operator expressions like "x + y" within
> > C++ templates", the documentation of BinaryOperator
> > (clang/include/clang/AST/Expr.h) and CXXOperatorCallExpr
> > (clang/include/clang/AST/ExprCXX.h) claim that if any of an operator's
> > arguments are type-dependent, it is represented with
> > CXXOperatorCallExpr. However,
> >
> >> template<typename T> void f(T x) {
> >> int n;
> >> x + n;
> >> x += n;
> >> }
> >> #pragma clang __debug dump f
> >
> > shows both + and += to use BinaryOperator (derived
> > CompoundAssignOperator for +=).
> >
> > Anything I'm missing?
>
That looks like a documentation bug to me. I believe the actual rule is
that CXXOperatorCallExpr is used if there is an associated set of functions
(because either the operator has been resolved to a specific function or
the operator is dependent and unqualified lookup found any potential
function candidates), and BinaryOperator is used if there are no associated
functions (because either the operator was resolved to a builtin operator
or the operator is dependent and unqualified lookup found nothing).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210615/5966af47/attachment.html>
More information about the llvm-dev
mailing list