[clang] [clang] add test verifying DR242 behavior (PR #201441)
Jess Ding via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 22 21:07:08 PDT 2026
https://github.com/jessding updated https://github.com/llvm/llvm-project/pull/201441
>From 6d0ac443e9fa162908117b6de54748ed00d10d02 Mon Sep 17 00:00:00 2001
From: Jess Ding <49802382+jessding at users.noreply.github.com>
Date: Wed, 3 Jun 2026 14:36:01 -0400
Subject: [PATCH 1/7] add test verifying DR242 behavior
---
clang/test/CXX/drs/cwg2xx.cpp | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/clang/test/CXX/drs/cwg2xx.cpp b/clang/test/CXX/drs/cwg2xx.cpp
index f81ab02e7d748..2ca9a84d0a03a 100644
--- a/clang/test/CXX/drs/cwg2xx.cpp
+++ b/clang/test/CXX/drs/cwg2xx.cpp
@@ -695,6 +695,37 @@ namespace cwg241 { // cwg241: 9
}
} // namespace cwg241
+namespace cwg242 { // cwg242: yes
+ struct A {};
+ struct I1 : A {};
+ struct I2 : A {};
+ struct D : I1, I2 {};
+
+ A *upcast(D *p) {
+ return (A *)(p);
+ /* expected-error at -1
+ {{ambiguous conversion from derived class 'D' to base class 'A':
+ struct cwg242::D -> I1 -> A
+ struct cwg242::D -> I2 -> A}}*/
+ }
+
+ D *downcast(A *p) {
+ return (D *)(p);
+ /* expected-error at -1
+ {{ambiguous cast from base 'cwg242::A' to derived 'cwg242::D':
+ A -> I1 -> struct cwg242::D
+ A -> I2 -> struct cwg242::D}}*/
+ }
+
+ struct V {};
+ struct B : virtual V {};
+
+ B *virt_downcast(V *p) {
+ return (B *)(p);
+ // expected-error at -1 {{cannot cast 'cwg242::V *' to 'B *' via virtual base 'cwg242::V'}}
+ }
+} // namespace cwg242
+
namespace cwg243 { // cwg243: 2.8
struct B;
struct A {
>From 00ae8200b17f9881d771cf20f7909cc2df4c4251 Mon Sep 17 00:00:00 2001
From: jessding <jessding at alum.mit.edu>
Date: Sat, 6 Jun 2026 16:06:54 -0400
Subject: [PATCH 2/7] Update earliest known clang defect resolution
availability to 2.8
---
clang/test/CXX/drs/cwg2xx.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/test/CXX/drs/cwg2xx.cpp b/clang/test/CXX/drs/cwg2xx.cpp
index 2ca9a84d0a03a..7568630e41dfe 100644
--- a/clang/test/CXX/drs/cwg2xx.cpp
+++ b/clang/test/CXX/drs/cwg2xx.cpp
@@ -695,7 +695,7 @@ namespace cwg241 { // cwg241: 9
}
} // namespace cwg241
-namespace cwg242 { // cwg242: yes
+namespace cwg242 { // cwg242: 2.8
struct A {};
struct I1 : A {};
struct I2 : A {};
>From c6701dfcd05091e10bd1c1d55bd8862841dec4d1 Mon Sep 17 00:00:00 2001
From: jessding <jessding at alum.mit.edu>
Date: Sat, 6 Jun 2026 16:27:37 -0400
Subject: [PATCH 3/7] update expected error strings
---
clang/test/CXX/drs/cwg2xx.cpp | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/clang/test/CXX/drs/cwg2xx.cpp b/clang/test/CXX/drs/cwg2xx.cpp
index 7568630e41dfe..30a38ac431caa 100644
--- a/clang/test/CXX/drs/cwg2xx.cpp
+++ b/clang/test/CXX/drs/cwg2xx.cpp
@@ -703,18 +703,12 @@ namespace cwg242 { // cwg242: 2.8
A *upcast(D *p) {
return (A *)(p);
- /* expected-error at -1
- {{ambiguous conversion from derived class 'D' to base class 'A':
- struct cwg242::D -> I1 -> A
- struct cwg242::D -> I2 -> A}}*/
+ // expected-error at -1 {{error: ambiguous conversion from derived class 'cwg242::D' to base class 'cwg242::A'}}
}
D *downcast(A *p) {
return (D *)(p);
- /* expected-error at -1
- {{ambiguous cast from base 'cwg242::A' to derived 'cwg242::D':
- A -> I1 -> struct cwg242::D
- A -> I2 -> struct cwg242::D}}*/
+ // expected-error at -1 {{ambiguous cast from base 'cwg242::A' to derived 'cwg242::D'}}
}
struct V {};
>From 6b0a08a7c8bb371b23f35cdbf82accfb53d7c34b Mon Sep 17 00:00:00 2001
From: jessding <jessding at alum.mit.edu>
Date: Sat, 6 Jun 2026 16:32:01 -0400
Subject: [PATCH 4/7] add reference cast and pointer-to-member conversion tests
---
clang/test/CXX/drs/cwg2xx.cpp | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/clang/test/CXX/drs/cwg2xx.cpp b/clang/test/CXX/drs/cwg2xx.cpp
index 30a38ac431caa..75a0573c05fab 100644
--- a/clang/test/CXX/drs/cwg2xx.cpp
+++ b/clang/test/CXX/drs/cwg2xx.cpp
@@ -718,6 +718,16 @@ namespace cwg242 { // cwg242: 2.8
return (B *)(p);
// expected-error at -1 {{cannot cast 'cwg242::V *' to 'B *' via virtual base 'cwg242::V'}}
}
+
+ A &ref_upcast(D &r) {
+ return (A &)(r);
+ // expected-error at -1 {{ambiguous conversion from derived class 'cwg242::D' to base class 'cwg242::A'}}
+ }
+
+ int D::*ptm_cast(int A::*p) {
+ return (int D::*)(p);
+ // expected-error at -1 {{ambiguous conversion from pointer to member of base class 'cwg242::A' to pointer to member of derived class 'cwg242::D'}}
+ }
} // namespace cwg242
namespace cwg243 { // cwg243: 2.8
>From fa538d83f2e8c77571bca5581608b1a199f8b55b Mon Sep 17 00:00:00 2001
From: jessding <jessding at alum.mit.edu>
Date: Mon, 22 Jun 2026 22:48:23 -0400
Subject: [PATCH 5/7] add reference downcast test
---
clang/test/CXX/drs/cwg2xx.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/clang/test/CXX/drs/cwg2xx.cpp b/clang/test/CXX/drs/cwg2xx.cpp
index 75a0573c05fab..833a9ff48ade0 100644
--- a/clang/test/CXX/drs/cwg2xx.cpp
+++ b/clang/test/CXX/drs/cwg2xx.cpp
@@ -724,6 +724,11 @@ namespace cwg242 { // cwg242: 2.8
// expected-error at -1 {{ambiguous conversion from derived class 'cwg242::D' to base class 'cwg242::A'}}
}
+ D &ref_downcast(A &r) {
+ return (D &)(r);
+ // expected-error at -1 {{ambiguous cast from base 'cwg242::A' to derived 'cwg242::D'}}
+ }
+
int D::*ptm_cast(int A::*p) {
return (int D::*)(p);
// expected-error at -1 {{ambiguous conversion from pointer to member of base class 'cwg242::A' to pointer to member of derived class 'cwg242::D'}}
>From 13e056b710030ca2edfd55b9cc79a215feb5c0f2 Mon Sep 17 00:00:00 2001
From: jessding <jessding at alum.mit.edu>
Date: Mon, 22 Jun 2026 22:48:42 -0400
Subject: [PATCH 6/7] update DR status page
---
clang/www/cxx_dr_status.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index c9f136ba26681..379e0f80b990f 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -1740,7 +1740,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td>[<a href="https://wg21.link/expr.cast">expr.cast</a>]</td>
<td>CD4</td>
<td>Interpretation of old-style casts</td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Clang 2.8</td>
</tr>
<tr id="243">
<td><a href="https://cplusplus.github.io/CWG/issues/243.html">243</a></td>
>From e84834fbdf95b3da6ad3030bee929fa7d9ae1e78 Mon Sep 17 00:00:00 2001
From: jessding <jessding at alum.mit.edu>
Date: Tue, 23 Jun 2026 00:00:42 -0400
Subject: [PATCH 7/7] add qual up/downcast test cases, and update earliest
supporting clang version from 2.8 to 3.0
---
clang/test/CXX/drs/cwg2xx.cpp | 43 ++++++++++++++++++++++++++++++-----
clang/www/cxx_dr_status.html | 2 +-
2 files changed, 38 insertions(+), 7 deletions(-)
diff --git a/clang/test/CXX/drs/cwg2xx.cpp b/clang/test/CXX/drs/cwg2xx.cpp
index 833a9ff48ade0..cc95f55892f7e 100644
--- a/clang/test/CXX/drs/cwg2xx.cpp
+++ b/clang/test/CXX/drs/cwg2xx.cpp
@@ -695,7 +695,7 @@ namespace cwg241 { // cwg241: 9
}
} // namespace cwg241
-namespace cwg242 { // cwg242: 2.8
+namespace cwg242 { // cwg242: 3.0
struct A {};
struct I1 : A {};
struct I2 : A {};
@@ -703,12 +703,18 @@ namespace cwg242 { // cwg242: 2.8
A *upcast(D *p) {
return (A *)(p);
- // expected-error at -1 {{error: ambiguous conversion from derived class 'cwg242::D' to base class 'cwg242::A'}}
+ /* expected-error at -1
+ {{ambiguous conversion from derived class 'D' to base class 'A':
+ struct cwg242::D -> I1 -> A
+ struct cwg242::D -> I2 -> A}}*/
}
D *downcast(A *p) {
return (D *)(p);
- // expected-error at -1 {{ambiguous cast from base 'cwg242::A' to derived 'cwg242::D'}}
+ /* expected-error at -1
+ {{ambiguous cast from base 'cwg242::A' to derived 'cwg242::D':
+ A -> I1 -> struct cwg242::D
+ A -> I2 -> struct cwg242::D}}*/
}
struct V {};
@@ -721,17 +727,42 @@ namespace cwg242 { // cwg242: 2.8
A &ref_upcast(D &r) {
return (A &)(r);
- // expected-error at -1 {{ambiguous conversion from derived class 'cwg242::D' to base class 'cwg242::A'}}
+ /* expected-error at -1
+ {{ambiguous conversion from derived class 'D' to base class 'A':
+ struct cwg242::D -> I1 -> A
+ struct cwg242::D -> I2 -> A}}*/
}
D &ref_downcast(A &r) {
return (D &)(r);
- // expected-error at -1 {{ambiguous cast from base 'cwg242::A' to derived 'cwg242::D'}}
+ /* expected-error at -1
+ {{ambiguous cast from base 'cwg242::A' to derived 'cwg242::D':
+ A -> I1 -> struct cwg242::D
+ A -> I2 -> struct cwg242::D}}*/
+ }
+
+ A *qual_upcast(const D *p) {
+ return (A *)(p);
+ /* expected-error at -1
+ {{ambiguous conversion from derived class 'D' to base class 'A':
+ struct cwg242::D -> I1 -> A
+ struct cwg242::D -> I2 -> A}}*/
+ }
+
+ D *qual_downcast(const A *p) {
+ return (D *)(p);
+ /* expected-error at -1
+ {{ambiguous cast from base 'cwg242::A' to derived 'cwg242::D':
+ A -> I1 -> struct cwg242::D
+ A -> I2 -> struct cwg242::D}}*/
}
int D::*ptm_cast(int A::*p) {
return (int D::*)(p);
- // expected-error at -1 {{ambiguous conversion from pointer to member of base class 'cwg242::A' to pointer to member of derived class 'cwg242::D'}}
+ /* expected-error at -1
+ {{ambiguous conversion from pointer to member of base class 'A' to pointer to member of derived class 'D':
+ struct cwg242::D -> I1 -> A
+ struct cwg242::D -> I2 -> A}}*/
}
} // namespace cwg242
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 379e0f80b990f..71a3438e5c592 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -1740,7 +1740,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td>[<a href="https://wg21.link/expr.cast">expr.cast</a>]</td>
<td>CD4</td>
<td>Interpretation of old-style casts</td>
- <td class="full" align="center">Clang 2.8</td>
+ <td class="full" align="center">Clang 3.0</td>
</tr>
<tr id="243">
<td><a href="https://cplusplus.github.io/CWG/issues/243.html">243</a></td>
More information about the cfe-commits
mailing list