[clang] [clang] fix expression classification for dependent binary operators (PR #159819)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 19 10:26:16 PDT 2025


https://github.com/mizvekov created https://github.com/llvm/llvm-project/pull/159819

This fixes a regression reported here: https://github.com/llvm/llvm-project/pull/159463#issuecomment-3312157416 Since this regression was never released, there are no release notes.

>From 21d07e400ab154a298cd383c68b94227f0f65c11 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov <mizvekov at gmail.com>
Date: Fri, 19 Sep 2025 14:23:49 -0300
Subject: [PATCH] [clang] fix expression classification for dependent binary
 operators

This fixes a regression reported here: https://github.com/llvm/llvm-project/pull/159463#issuecomment-3312157416
Since this regression was never released, there are no release notes.
---
 clang/lib/AST/ExprClassification.cpp          | 7 +++++++
 clang/test/SemaTemplate/temp_arg_template.cpp | 6 ++++++
 2 files changed, 13 insertions(+)

diff --git a/clang/lib/AST/ExprClassification.cpp b/clang/lib/AST/ExprClassification.cpp
index ad66335138a42..efe72137631a2 100644
--- a/clang/lib/AST/ExprClassification.cpp
+++ b/clang/lib/AST/ExprClassification.cpp
@@ -601,6 +601,13 @@ static Cl::Kinds ClassifyMemberExpr(ASTContext &Ctx, const MemberExpr *E) {
 static Cl::Kinds ClassifyBinaryOp(ASTContext &Ctx, const BinaryOperator *E) {
   assert(Ctx.getLangOpts().CPlusPlus &&
          "This is only relevant for C++.");
+
+  // For binary operators which are unknown due to type dependence, the convention
+  // is to classify them as a prvalue. This does not matter much, but it needs
+  // to agree with how they are created.
+  if (E->getType() == Ctx.DependentTy)
+    return Cl::CL_PRValue;
+
   // C++ [expr.ass]p1: All [...] return an lvalue referring to the left operand.
   // Except we override this for writes to ObjC properties.
   if (E->isAssignmentOp())
diff --git a/clang/test/SemaTemplate/temp_arg_template.cpp b/clang/test/SemaTemplate/temp_arg_template.cpp
index 431e19741ece9..c9576e2057e53 100644
--- a/clang/test/SemaTemplate/temp_arg_template.cpp
+++ b/clang/test/SemaTemplate/temp_arg_template.cpp
@@ -149,6 +149,12 @@ namespace CheckDependentNonTypeParamTypes {
   };
   // FIXME: This should be rejected, as there are no valid instantiations for E<char>::F
   template struct E<char>;
+
+#if __cplusplus >= 201703L
+  template<template<auto> class TT, class V> struct G {
+    using type = TT<((void)0, V::value)>;
+  };
+#endif
 }
 
 namespace PR32185 {



More information about the cfe-commits mailing list