[PATCH] D148035: [clang] Add test for CWG1837

Vlad Serebrennikov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 11 11:52:18 PDT 2023


Endill created this revision.
Endill added a reviewer: clang-language-wg.
Herald added a project: All.
Endill requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

P1787 <https://wg21.link/p1787>: CWG1837 is resolved by restricting this to referring to the innermost enclosing class.
Wording: see changes to [expr.prim.this] and [expr.prim.lambda]


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148035

Files:
  clang/test/CXX/drs/dr18xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===================================================================
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -10829,7 +10829,7 @@
     <td><a href="https://wg21.link/cwg1837">1837</a></td>
     <td>CD6</td>
     <td>Use of <TT>this</TT> in <TT>friend</TT> and local class declarations</td>
-    <td class="none" align="center">Unknown</td>
+    <td class="full" align="center">Clang 3.3</td>
   </tr>
   <tr id="1838">
     <td><a href="https://wg21.link/cwg1838">1838</a></td>
Index: clang/test/CXX/drs/dr18xx.cpp
===================================================================
--- clang/test/CXX/drs/dr18xx.cpp
+++ clang/test/CXX/drs/dr18xx.cpp
@@ -2,7 +2,8 @@
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++2a -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2b -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 
 #if __cplusplus < 201103L
 // expected-error at +1 {{variadic macro}}
@@ -59,6 +60,43 @@
 #endif
 }
 
+namespace dr1837 { // dr1837: 3.3
+#if __cplusplus >= 201103L
+  template <typename T>
+  struct Fish { static const bool value = true; };
+
+  struct Other {
+    int p();
+    auto q() -> decltype(p()) *;
+  };
+
+  class Outer {
+    friend auto Other::q() -> decltype(this->p()) *; // expected-error {{invalid use of 'this'}}
+    int g();
+    int f() {
+      extern void f(decltype(this->g()) *);
+      struct Inner {
+        static_assert(Fish<decltype(this->g())>::value, ""); // expected-error {{invalid use of 'this'}}
+        enum { X = Fish<decltype(this->f())>::value }; // expected-error {{invalid use of 'this'}}
+        struct Inner2 : Fish<decltype(this->g())> { }; // expected-error {{invalid use of 'this'}}
+        friend void f(decltype(this->g()) *); // expected-error {{invalid use of 'this'}}
+        friend auto Other::q() -> decltype(this->p()) *; // expected-error {{invalid use of 'this'}}
+      };
+      return 0;
+    }
+  };
+
+  struct A {
+    int f();
+    auto b = [] {
+      struct Local {
+        static_assert(sizeof(this->f()) == sizeof(int), "");
+      };
+    };
+  };
+#endif
+}
+
 namespace dr1872 { // dr1872: 9
 #if __cplusplus >= 201103L
   template<typename T> struct A : T {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148035.512535.patch
Type: text/x-patch
Size: 2939 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230411/69fe6603/attachment.bin>


More information about the cfe-commits mailing list