[clang] [Clang] Warning as error for fold expressions over comparison operators (PR #136836)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Thu May 1 03:22:54 PDT 2025
================
@@ -132,3 +132,30 @@ bool f();
template <typename... T>
void g(bool = (f<T>() || ...));
}
+
+
+namespace comparison_warning {
+ struct S {
+ bool operator<(const S&) const;
+ bool operator<(int) const;
+ bool operator==(const S&) const;
+ };
+
+ template <typename...T>
+ void f(T... ts) {
+ (void)(ts == ...);
+ // expected-error at -1 2{{comparison in fold expression would evaluate to '(X == Y) == Z'}}
+ (void)(ts < ...);
+ // expected-error at -1 2{{comparison in fold expression would evaluate to '(X < Y) < Z'}}
+ (void)(... < ts);
+ // expected-error at -1 2{{comparison in fold expression would evaluate to '(X < Y) < Z'}}
+ }
+
+ void test() {
+ f(0, 1, 2); // expected-note{{in instantiation}}
+ f(0, 1); // expected-note{{in instantiation}}
----------------
zyn0217 wrote:
Hmmm. It looks strange to me if we warn for '0 < 1'
https://github.com/llvm/llvm-project/pull/136836
More information about the cfe-commits
mailing list