Skip to content

Commit 658ec85

Browse files
authored
[clang] Add test for CWG170 "Pointer-to-member conversions" (#121667)
This patch adds test for [CWG170](https://cplusplus.github.io/CWG/issues/170.html). 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](https://wg21.link/p0149r0) "Generalised member pointers".
1 parent 7aebacb commit 658ec85

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

clang/test/CXX/drs/cwg1xx.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,26 @@ namespace cwg169 { // cwg169: 3.4
10761076
};
10771077
} // namespace cwg169
10781078

1079+
namespace cwg170 { // cwg170: 3.1
1080+
#if __cplusplus >= 201103L
1081+
struct A {};
1082+
struct B : A { int i; };
1083+
struct C : A {};
1084+
struct D : C {};
1085+
1086+
constexpr int f(int A::*) { return 0; }
1087+
constexpr int g(int C::*) { return 0; }
1088+
constexpr int h(int D::*) { return 0; }
1089+
1090+
constexpr auto p = static_cast<int A::*>(&B::i);
1091+
constexpr auto q = f(p);
1092+
constexpr auto r = g(p);
1093+
// since-cxx11-error@-1 {{constexpr variable 'r' must be initialized by a constant expression}}
1094+
constexpr auto s = h(p);
1095+
// since-cxx11-error@-1 {{constexpr variable 's' must be initialized by a constant expression}}
1096+
#endif
1097+
} // namespace cwg170
1098+
10791099
namespace { // cwg171: 3.4
10801100
int cwg171a;
10811101
}

clang/www/cxx_dr_status.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
10651065
<td><a href="https://cplusplus.github.io/CWG/issues/170.html">170</a></td>
10661066
<td>DRWP</td>
10671067
<td>Pointer-to-member conversions</td>
1068-
<td class="unknown" align="center">Unknown</td>
1068+
<td class="full" align="center">Clang 3.1</td>
10691069
</tr>
10701070
<tr id="171">
10711071
<td><a href="https://cplusplus.github.io/CWG/issues/171.html">171</a></td>

0 commit comments

Comments
 (0)