[clang] [clang] add test verifying DR242 behavior (PR #201441)
Jess Ding via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 6 13:34:20 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/4] 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/4] 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/4] 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/4] 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
More information about the cfe-commits
mailing list