[PATCH] D138387: [Clang] Implement static operator[]

2022-11-29 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3faf1f17a5c3: [Clang] Implement static operator[] (authored 
by royjacobson).

Changed prior to commit:
  https://reviews.llvm.org/D138387?vs=477550=478493#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138387/new/

https://reviews.llvm.org/D138387

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/over/over.oper/p7.cpp
  clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp
  clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1518,7 +1518,7 @@
 
   static operator[]
   https://wg21.link/P2589R1;>P2589R1
-  No
+  16
 
 
   Permitting static constexpr variables in constexpr functions (DR)
Index: clang/test/Lexer/cxx-features.cpp
===
--- clang/test/Lexer/cxx-features.cpp
+++ clang/test/Lexer/cxx-features.cpp
@@ -43,7 +43,7 @@
 #error "wrong value for __cpp_if_consteval"
 #endif
 
-#if check(multidimensional_subscript, 0, 0, 0, 0, 0, 202110)
+#if check(multidimensional_subscript, 0, 0, 0, 0, 0, 202211)
 #error "wrong value for __cpp_multidimensional_subscript"
 #endif
 
Index: clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp
@@ -0,0 +1,66 @@
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -triple x86_64-linux -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -triple x86_64-windows-msvc -o - | FileCheck %s
+
+struct Functor {
+  static int operator[](int x, int y) {
+return x + y;
+  }
+};
+
+void call_static_subscript_operator() {
+  Functor f;
+  f[101, 102];
+  f.operator[](201, 202);
+  Functor{}[301, 302];
+  Functor::operator[](401, 402);
+}
+
+// CHECK:  define {{.*}}call_static_subscript_operator{{.*}}
+// CHECK-NEXT: entry:
+// CHECK:{{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 101, i32 noundef 102)
+// CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 201, i32 noundef 202)
+// CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 301, i32 noundef 302)
+// CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 401, i32 noundef 402)
+// CHECK-NEXT:   ret void
+// CHECK-NEXT: }
+
+struct FunctorConsteval {
+  consteval static int operator[](int x, int y) {
+  return x + y;
+  }
+};
+
+struct FunctorConstexpr {
+  constexpr static int operator[](int x, int y) {
+  return x + y;
+  }
+};
+
+void test_consteval_constexpr() {
+  int x = 0;
+  int y = FunctorConstexpr{}[x, 2];
+  constexpr int z1 = FunctorConsteval{}[2, 2];
+  constexpr int z2 = FunctorConstexpr{}[2, 2];
+  
+  static_assert(z1 == 4);
+  static_assert(z2 == 4);
+}
+
+template 
+struct DepFunctor {
+  static int operator[](T t) {
+return int(t);
+  }
+};
+
+void test_dep_functors() {
+  int x = DepFunctor{}[1.0f];
+  int y = DepFunctor{}[true];
+}
+
+// CHECK:  define {{.*}}test_dep_functors{{.*}}
+// CHECK-NEXT: entry:
+// CHECK:%call = call noundef i32 {{.*}}DepFunctor{{.*}}(float noundef 1.00e+00)
+// CHECK:%call1 = call noundef i32 {{.*}}DepFunctor{{.*}}(i1 noundef zeroext true)
+// CHECK:ret void
+// CHECK-NEXT: }
Index: clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp
===
--- clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp
+++ clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp
@@ -28,6 +28,7 @@
   f(101, 102);
   f.operator()(201, 202);
   Functor{}(301, 302);
+  Functor::operator()(401, 402);
 }
 
 // CHECK:  define {{.*}}call_static_call_operator{{.*}}
@@ -35,6 +36,7 @@
 // CHECK:{{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 101, i32 noundef 102)
 // CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 201, i32 noundef 202)
 // CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 301, i32 noundef 302)
+// CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 401, i32 noundef 402)
 // CHECK-NEXT:   ret void
 // CHECK-NEXT: }
 
Index: clang/test/CXX/over/over.oper/p7.cpp
===
--- clang/test/CXX/over/over.oper/p7.cpp
+++ clang/test/CXX/over/over.oper/p7.cpp
@@ -5,14 +5,19 @@
 
 struct Functor {
   static int operator()(int a, int b);
-  // cxx11-warning@-1 {{is a C++2b extension}}
-  // precxx2b-warning@-2 

[PATCH] D138387: [Clang] Implement static operator[]

2022-11-28 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138387/new/

https://reviews.llvm.org/D138387

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138387: [Clang] Implement static operator[]

2022-11-23 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson marked an inline comment as done.
royjacobson added a comment.

In D138387#3944211 , @cor3ntin wrote:

> Beside the formatting nitpick this looks good

Thanks! I'll wait until next week to let other people have a chance to take a 
look.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138387/new/

https://reviews.llvm.org/D138387

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138387: [Clang] Implement static operator[]

2022-11-23 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson marked 3 inline comments as done.
royjacobson added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:14462-14467
+  RLoc, CurFPFeatureOverrides());
+else
+  TheCall =
+  CallExpr::Create(Context, FnExpr.get(), MethodArgs, ResultTy, VK,
+   RLoc, CurFPFeatureOverrides());
+

cor3ntin wrote:
> This looks weird, did you clang-format?
clang-format insists on this, personally I wouldn't write it like this either :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138387/new/

https://reviews.llvm.org/D138387

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138387: [Clang] Implement static operator[]

2022-11-23 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 477550.
royjacobson added a comment.

Add a missing test case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138387/new/

https://reviews.llvm.org/D138387

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/over/over.oper/p7.cpp
  clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp
  clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1518,7 +1518,7 @@
 
   static operator[]
   https://wg21.link/P2589R1;>P2589R1
-  No
+  16
 
 
   Permitting static constexpr variables in constexpr functions (DR)
Index: clang/test/Lexer/cxx-features.cpp
===
--- clang/test/Lexer/cxx-features.cpp
+++ clang/test/Lexer/cxx-features.cpp
@@ -43,7 +43,7 @@
 #error "wrong value for __cpp_if_consteval"
 #endif
 
-#if check(multidimensional_subscript, 0, 0, 0, 0, 0, 202110)
+#if check(multidimensional_subscript, 0, 0, 0, 0, 0, 202211)
 #error "wrong value for __cpp_multidimensional_subscript"
 #endif
 
Index: clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp
@@ -0,0 +1,66 @@
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -triple x86_64-linux -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -triple x86_64-windows-msvc -o - | FileCheck %s
+
+struct Functor {
+  static int operator[](int x, int y) {
+return x + y;
+  }
+};
+
+void call_static_subscript_operator() {
+  Functor f;
+  f[101, 102];
+  f.operator[](201, 202);
+  Functor{}[301, 302];
+  Functor::operator[](401, 402);
+}
+
+// CHECK:  define {{.*}}call_static_subscript_operator{{.*}}
+// CHECK-NEXT: entry:
+// CHECK:{{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 101, i32 noundef 102)
+// CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 201, i32 noundef 202)
+// CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 301, i32 noundef 302)
+// CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 401, i32 noundef 402)
+// CHECK-NEXT:   ret void
+// CHECK-NEXT: }
+
+struct FunctorConsteval {
+  consteval static int operator[](int x, int y) {
+  return x + y;
+  }
+};
+
+struct FunctorConstexpr {
+  constexpr static int operator[](int x, int y) {
+  return x + y;
+  }
+};
+
+void test_consteval_constexpr() {
+  int x = 0;
+  int y = FunctorConstexpr{}[x, 2];
+  constexpr int z1 = FunctorConsteval{}[2, 2];
+  constexpr int z2 = FunctorConstexpr{}[2, 2];
+  
+  static_assert(z1 == 4);
+  static_assert(z2 == 4);
+}
+
+template 
+struct DepFunctor {
+  static int operator[](T t) {
+return int(t);
+  }
+};
+
+void test_dep_functors() {
+  int x = DepFunctor{}[1.0f];
+  int y = DepFunctor{}[true];
+}
+
+// CHECK:  define {{.*}}test_dep_functors{{.*}}
+// CHECK-NEXT: entry:
+// CHECK:%call = call noundef i32 {{.*}}DepFunctor{{.*}}(float noundef 1.00e+00)
+// CHECK:%call1 = call noundef i32 {{.*}}DepFunctor{{.*}}(i1 noundef zeroext true)
+// CHECK:ret void
+// CHECK-NEXT: }
Index: clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp
===
--- clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp
+++ clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp
@@ -28,6 +28,7 @@
   f(101, 102);
   f.operator()(201, 202);
   Functor{}(301, 302);
+  Functor::operator()(401, 402);
 }
 
 // CHECK:  define {{.*}}call_static_call_operator{{.*}}
@@ -35,6 +36,7 @@
 // CHECK:{{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 101, i32 noundef 102)
 // CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 201, i32 noundef 202)
 // CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 301, i32 noundef 302)
+// CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 401, i32 noundef 402)
 // CHECK-NEXT:   ret void
 // CHECK-NEXT: }
 
Index: clang/test/CXX/over/over.oper/p7.cpp
===
--- clang/test/CXX/over/over.oper/p7.cpp
+++ clang/test/CXX/over/over.oper/p7.cpp
@@ -5,14 +5,19 @@
 
 struct Functor {
   static int operator()(int a, int b);
-  // cxx11-warning@-1 {{is a C++2b extension}}
-  // precxx2b-warning@-2 {{declaring overloaded 'operator()' as 'static' is a C++2b extension}}
+  static int operator[](int a1);
+  // cxx11-warning@-2 {{declaring 

[PATCH] D138387: [Clang] Implement static operator[]

2022-11-22 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

Beside the formatting nitpick this looks good




Comment at: clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp:14
+  f.operator[](201, 202);
+  Functor{}[301, 302];
+}

I think this is missing a test like
`Functor::operator[](42, 42)` for completeness


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138387/new/

https://reviews.llvm.org/D138387

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138387: [Clang] Implement static operator[]

2022-11-21 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:14462-14467
+  RLoc, CurFPFeatureOverrides());
+else
+  TheCall =
+  CallExpr::Create(Context, FnExpr.get(), MethodArgs, ResultTy, VK,
+   RLoc, CurFPFeatureOverrides());
+

This looks weird, did you clang-format?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138387/new/

https://reviews.llvm.org/D138387

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138387: [Clang] Implement static operator[]

2022-11-21 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:9111-9115
 def ext_operator_overload_static : ExtWarn<
   "declaring overloaded %0 as 'static' is a C++2b extension">,
   InGroup, DefaultIgnore;
-def err_call_operator_overload_static : ExtWarn<
+def err_future_operator_overload_static : ExtWarn<
   "declaring overloaded %0 as 'static' is a C++2b extension">, InGroup;

cor3ntin wrote:
> Hum, I did not notice that before but this looks wrong.
> If I get that right, this is how it's usually done.
> 
> ie it should not be `err_` (it's a warning) and in C++23 mode it's not an 
> ExtWarn (which are turned into error in pendantic mode afaik). There are many 
> similar patterns in the same file
> 
> 
thanks! looks much cleaner now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138387/new/

https://reviews.llvm.org/D138387

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138387: [Clang] Implement static operator[]

2022-11-21 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 476975.
royjacobson added a comment.

1. Update warnings according to Corentin's comment
2. Somehow I missed the CodeGen was completely broken. Made a few necessary 
follow up changes in SemaOverload and ran the tests this time...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138387/new/

https://reviews.llvm.org/D138387

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/over/over.oper/p7.cpp
  clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1518,7 +1518,7 @@
 
   static operator[]
   https://wg21.link/P2589R1;>P2589R1
-  No
+  16
 
 
   Permitting static constexpr variables in constexpr functions (DR)
Index: clang/test/Lexer/cxx-features.cpp
===
--- clang/test/Lexer/cxx-features.cpp
+++ clang/test/Lexer/cxx-features.cpp
@@ -43,7 +43,7 @@
 #error "wrong value for __cpp_if_consteval"
 #endif
 
-#if check(multidimensional_subscript, 0, 0, 0, 0, 0, 202110)
+#if check(multidimensional_subscript, 0, 0, 0, 0, 0, 202211)
 #error "wrong value for __cpp_multidimensional_subscript"
 #endif
 
Index: clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp
@@ -0,0 +1,64 @@
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -triple x86_64-linux -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -triple x86_64-windows-msvc -o - | FileCheck %s
+
+struct Functor {
+  static int operator[](int x, int y) {
+return x + y;
+  }
+};
+
+void call_static_subscript_operator() {
+  Functor f;
+  f[101, 102];
+  f.operator[](201, 202);
+  Functor{}[301, 302];
+}
+
+// CHECK:  define {{.*}}call_static_subscript_operator{{.*}}
+// CHECK-NEXT: entry:
+// CHECK:{{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 101, i32 noundef 102)
+// CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 201, i32 noundef 202)
+// CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 301, i32 noundef 302)
+// CHECK-NEXT:   ret void
+// CHECK-NEXT: }
+
+struct FunctorConsteval {
+  consteval static int operator[](int x, int y) {
+  return x + y;
+  }
+};
+
+struct FunctorConstexpr {
+  constexpr static int operator[](int x, int y) {
+  return x + y;
+  }
+};
+
+void test_consteval_constexpr() {
+  int x = 0;
+  int y = FunctorConstexpr{}[x, 2];
+  constexpr int z1 = FunctorConsteval{}[2, 2];
+  constexpr int z2 = FunctorConstexpr{}[2, 2];
+  
+  static_assert(z1 == 4);
+  static_assert(z2 == 4);
+}
+
+template 
+struct DepFunctor {
+  static int operator[](T t) {
+return int(t);
+  }
+};
+
+void test_dep_functors() {
+  int x = DepFunctor{}[1.0f];
+  int y = DepFunctor{}[true];
+}
+
+// CHECK:  define {{.*}}test_dep_functors{{.*}}
+// CHECK-NEXT: entry:
+// CHECK:%call = call noundef i32 {{.*}}DepFunctor{{.*}}(float noundef 1.00e+00)
+// CHECK:%call1 = call noundef i32 {{.*}}DepFunctor{{.*}}(i1 noundef zeroext true)
+// CHECK:ret void
+// CHECK-NEXT: }
Index: clang/test/CXX/over/over.oper/p7.cpp
===
--- clang/test/CXX/over/over.oper/p7.cpp
+++ clang/test/CXX/over/over.oper/p7.cpp
@@ -5,14 +5,19 @@
 
 struct Functor {
   static int operator()(int a, int b);
-  // cxx11-warning@-1 {{is a C++2b extension}}
-  // precxx2b-warning@-2 {{declaring overloaded 'operator()' as 'static' is a C++2b extension}}
+  static int operator[](int a1);
+  // cxx11-warning@-2 {{declaring overloaded 'operator()' as 'static' is a C++2b extension}}
+  // cxx11-warning@-2 {{declaring overloaded 'operator[]' as 'static' is a C++2b extension}}
+  // precxx2b-warning@-4 {{incompatible with C++ standards before C++2b}}
+  // precxx2b-warning@-4 {{incompatible with C++ standards before C++2b}}
 };
 
 struct InvalidParsing1 {
   extern int operator()(int a, int b);  // expected-error {{storage class specified}}
+  extern int operator[](int a1);  // expected-error {{storage class specified}}
 };
 
 struct InvalidParsing2 {
   extern static int operator()(int a, int b);  // expected-error {{storage class specified}} // expected-error {{cannot combine with previous 'extern' declaration specifier}}
+  extern static int operator[](int a);  // expected-error {{storage class specified}} // expected-error {{cannot combine with previous 'extern' declaration specifier}}
 };
Index: 

[PATCH] D138387: [Clang] Implement static operator[]

2022-11-20 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

Thanks for working on this, it was fast!
It looks good except for an issue with the diagnostic (which was partly 
pre-existing)




Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:9111-9115
 def ext_operator_overload_static : ExtWarn<
   "declaring overloaded %0 as 'static' is a C++2b extension">,
   InGroup, DefaultIgnore;
-def err_call_operator_overload_static : ExtWarn<
+def err_future_operator_overload_static : ExtWarn<
   "declaring overloaded %0 as 'static' is a C++2b extension">, InGroup;

Hum, I did not notice that before but this looks wrong.
If I get that right, this is how it's usually done.

ie it should not be `err_` (it's a warning) and in C++23 mode it's not an 
ExtWarn (which are turned into error in pendantic mode afaik). There are many 
similar patterns in the same file




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138387/new/

https://reviews.llvm.org/D138387

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138387: [Clang] Implement static operator[]

2022-11-20 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
royjacobson added reviewers: cor3ntin, erichkeane.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

After accepted in Kona, update the code to accept static operator[]
as well.

No big code changes, just accept this in SemaDeclCXX and update
feature macros + tests accordingly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D138387

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/over/over.oper/p7.cpp
  clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1518,7 +1518,7 @@
 
   static operator[]
   https://wg21.link/P2589R1;>P2589R1
-  No
+  16
 
 
   Permitting static constexpr variables in constexpr functions (DR)
Index: clang/test/Lexer/cxx-features.cpp
===
--- clang/test/Lexer/cxx-features.cpp
+++ clang/test/Lexer/cxx-features.cpp
@@ -43,7 +43,7 @@
 #error "wrong value for __cpp_if_consteval"
 #endif
 
-#if check(multidimensional_subscript, 0, 0, 0, 0, 0, 202110)
+#if check(multidimensional_subscript, 0, 0, 0, 0, 0, 202211)
 #error "wrong value for __cpp_multidimensional_subscript"
 #endif
 
Index: clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp
@@ -0,0 +1,64 @@
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -triple x86_64-linux -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++2b %s -emit-llvm -triple x86_64-windows-msvc -o - | FileCheck %s
+
+struct Functor {
+  static int operator[](int x, int y) {
+return x + y;
+  }
+};
+
+void call_static_subscript_operator[] {
+  Functor f;
+  f[101, 102];
+  f.operator[](201, 202);
+  Functor{}[301, 302];
+}
+
+// CHECK:  define {{.*}}call_static_subscript_operator{{.*}}
+// CHECK-NEXT: entry:
+// CHECK:{{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 101, i32 noundef 102)
+// CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 201, i32 noundef 202)
+// CHECK-NEXT:   {{.*}} = call noundef i32 {{.*}}Functor{{.*}}(i32 noundef 301, i32 noundef 302)
+// CHECK-NEXT:   ret void
+// CHECK-NEXT: }
+
+struct FunctorConsteval {
+  consteval static int operator[](int x, int y) {
+  return x + y;
+  }
+};
+
+struct FunctorConstexpr {
+  constexpr static int operator[](int x, int y) {
+  return x + y;
+  }
+};
+
+void test_consteval_constexpr() {
+  int x = 0;
+  int y = FunctorConstexpr{}[x, 2];
+  constexpr int z1 = FunctorConsteval{}[2, 2];
+  constexpr int z2 = FunctorConstexpr{}[2, 2];
+  
+  static_assert(z1 == 4);
+  static_assert(z2 == 4);
+}
+
+template 
+struct DepFunctor {
+  static int operator[](T t) {
+return int(t);
+  }
+};
+
+void test_dep_functors() {
+  int x = DepFunctor{}[1.0f];
+  int y = DepFunctor{}[true];
+}
+
+// CHECK:  define {{.*}}test_dep_functors{{.*}}
+// CHECK-NEXT: entry:
+// CHECK:%call = call noundef i32 {{.*}}DepFunctor{{.*}}(float noundef 1.00e+00)
+// CHECK:%call1 = call noundef i32 {{.*}}DepFunctor{{.*}}(i1 noundef zeroext true)
+// CHECK:ret void
+// CHECK-NEXT: }
Index: clang/test/CXX/over/over.oper/p7.cpp
===
--- clang/test/CXX/over/over.oper/p7.cpp
+++ clang/test/CXX/over/over.oper/p7.cpp
@@ -5,14 +5,19 @@
 
 struct Functor {
   static int operator()(int a, int b);
-  // cxx11-warning@-1 {{is a C++2b extension}}
-  // precxx2b-warning@-2 {{declaring overloaded 'operator()' as 'static' is a C++2b extension}}
+  static int operator[](int a1);
+  // cxx11-warning@-2 {{is a C++2b extension}}
+  // cxx11-warning@-2 {{is a C++2b extension}}
+  // precxx2b-warning@-4 {{declaring overloaded 'operator()' as 'static' is a C++2b extension}}
+  // precxx2b-warning@-4 {{declaring overloaded 'operator[]' as 'static' is a C++2b extension}}
 };
 
 struct InvalidParsing1 {
   extern int operator()(int a, int b);  // expected-error {{storage class specified}}
+  extern int operator[](int a1);  // expected-error {{storage class specified}}
 };
 
 struct InvalidParsing2 {
   extern static int operator()(int a, int b);  // expected-error {{storage class specified}} // expected-error {{cannot combine with previous 'extern' declaration specifier}}
+  extern static int operator[](int a);  // expected-error {{storage class specified}} // expected-error {{cannot combine with previous 'extern' declaration specifier}}
 };
Index: