Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang] Add test for CWG170 "Pointer-to-member conversions" #121667

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Endilll
Copy link
Contributor

@Endilll Endilll commented Jan 4, 2025

This patch adds test for CWG170. The resolution adds explicit undefined behavior, so I think the best we can do is to put the test into constexpr evaluator. Change to [expr.static.cast] is not tested, because it was a drive-by fix that removed an impossible case (I confirmed it using minutes). Minutes mention several times a comprehensive paper in this design space which no one seem to remember. I believe it's P0149R0 "Generalised member pointers".

@Endilll Endilll added clang Clang issues not falling into any other category c++ labels Jan 4, 2025
@Endilll Endilll requested review from cor3ntin and shafik January 4, 2025 21:17
@llvmbot
Copy link
Member

llvmbot commented Jan 4, 2025

@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)

Changes

This patch adds test for CWG170. The resolution adds explicit undefined behavior, so I think the best we can do is to put the test into constexpr evaluator. Change to [expr.static.cast] is not tested, because it was a drive-by fix that removed an impossible case (I confirmed it using minutes). Minutes mention several times a comprehensive paper in this design space which no one seem to remember. I believe it's P0149R0 "Generalised member pointers".


Full diff: https://github.com/llvm/llvm-project/pull/121667.diff

2 Files Affected:

  • (modified) clang/test/CXX/drs/cwg1xx.cpp (+20)
  • (modified) clang/www/cxx_dr_status.html (+1-1)
diff --git a/clang/test/CXX/drs/cwg1xx.cpp b/clang/test/CXX/drs/cwg1xx.cpp
index 6aec8b65c91f12..0110c711d6dd89 100644
--- a/clang/test/CXX/drs/cwg1xx.cpp
+++ b/clang/test/CXX/drs/cwg1xx.cpp
@@ -1074,6 +1074,26 @@ namespace cwg169 { // cwg169: yes
   };
 }
 
+namespace cwg170 { // cwg170: 3.1
+#if __cplusplus >= 201103L
+struct A {};
+struct B : A { int i; };
+struct C : A {};
+struct D : C {};
+
+constexpr int f(int A::*) { return 0; }
+constexpr int g(int C::*) { return 0; }
+constexpr int h(int D::*) { return 0; }
+
+constexpr auto p = static_cast<int A::*>(&B::i);
+constexpr auto q = f(p);
+constexpr auto r = g(p);
+// since-cxx11-error@-1 {{constexpr variable 'r' must be initialized by a constant expression}}
+constexpr auto s = h(p);
+// since-cxx11-error@-1 {{constexpr variable 's' must be initialized by a constant expression}}
+#endif
+} // namespace cwg170
+
 namespace { // cwg171: 3.4
   int cwg171a;
 }
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index c069e155fd547c..935411e778b251 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -1065,7 +1065,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
     <td><a href="https://cplusplus.github.io/CWG/issues/170.html">170</a></td>
     <td>DRWP</td>
     <td>Pointer-to-member conversions</td>
-    <td class="unknown" align="center">Unknown</td>
+    <td class="full" align="center">Clang 3.1</td>
   </tr>
   <tr id="171">
     <td><a href="https://cplusplus.github.io/CWG/issues/171.html">171</a></td>

@cor3ntin cor3ntin added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants