Skip to content

Commit

Permalink
[clang] Add tests for DRs about inheriting constructors (#79981)
Browse files Browse the repository at this point in the history
Covers CWG issues
[1150](https://cplusplus.github.io/CWG/issues/1150.html),
[1487](https://cplusplus.github.io/CWG/issues/1487.html),
[1567](https://cplusplus.github.io/CWG/issues/1567.html),
[1738](https://cplusplus.github.io/CWG/issues/1738.html),
[2273](https://cplusplus.github.io/CWG/issues/2273.html),
[2277](https://cplusplus.github.io/CWG/issues/2277.html),
[2356](https://cplusplus.github.io/CWG/issues/2356.html),
[2504](https://cplusplus.github.io/CWG/issues/2504.html).

On top of the wording in proposed resolutions,
[P0136R1](https://wg21.link/p0136r1) "Rewording inheriting constructors
(core issue 1941 et al)" is a very relevant paper.

Note that status for 1738 `sup P0136R1` is not officially recognized by
CWG, but saying `yes` or `no` seems even more confusing to me. Official
resolution is to reject certain code, but Clang is the only
implementation that still rejects it to this day:
https://godbolt.org/z/b1W8jc1o5. GCC rejected it until 9, now it's
accepted: https://godbolt.org/z/of6oh4sdT
  • Loading branch information
Endilll committed Feb 9, 2024
1 parent fcb5920 commit 50c5107
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 8 deletions.
2 changes: 2 additions & 0 deletions clang/test/CXX/drs/dr11xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,5 @@ namespace dr1113 { // dr1113: partial
}
void g() { f(); }
}

// dr1150: na
24 changes: 24 additions & 0 deletions clang/test/CXX/drs/dr14xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,30 @@ enum E2 : S<E2>::I { e };
#endif
} // namespace dr1482

namespace dr1487 { // dr1487: 3.3
#if __cplusplus >= 201103L
struct A { // #dr1482-A
struct B {
using A::A;
// since-cxx11-error@-1 {{using declaration refers into 'A::', which is not a base class of 'B'}}
};

struct C : A {
// since-cxx11-error@-1 {{base class has incomplete type}}
// since-cxx11-note@#dr1482-A {{definition of 'dr1487::A' is not complete until the closing '}'}}
using A::A;
// since-cxx11-error@-1 {{using declaration refers into 'A::', which is not a base class of 'C'}}
};

struct D;
};

struct D : A {
using A::A;
};
#endif
} // namespace dr1487

namespace dr1490 { // dr1490: 3.7 c++11
#if __cplusplus >= 201103L
// List-initialization from a string literal
Expand Down
39 changes: 39 additions & 0 deletions clang/test/CXX/drs/dr15xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,45 @@ namespace dr1563 { // dr1563: yes
#endif
}

namespace dr1567 { // dr1567: 3.3
#if __cplusplus >= 201103L
struct B;
struct A {
A(const A&);
A(const B&) = delete;
A(A&&);
A(B&&) = delete;
A(int); // #dr1567-A-int
};

struct B: A { // #dr1567-B
using A::A; // #dr1567-using-A
B(double); // #dr1567-B-double
};

A a{0};
B b{1.0};
// Good, deleted converting ctors are not inherited as copy/move ctors
B b2{b};
B b3{B{1.0}};
// Good, copy/move ctors are not inherited
B b4{a};
// since-cxx11-error@-1 {{no matching constructor for initialization of 'B'}}
// since-cxx11-note@#dr1567-A-int {{candidate inherited constructor not viable: no known conversion from 'A' to 'int' for 1st argument}}
// since-cxx11-note@#dr1567-using-A {{constructor from base class 'A' inherited here}}
// since-cxx11-note@#dr1567-B {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'A' to 'const B' for 1st argument}}
// since-cxx11-note@#dr1567-B {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'A' to 'B' for 1st argument}}
// since-cxx11-note@#dr1567-B-double {{candidate constructor not viable: no known conversion from 'A' to 'double' for 1st argument}}
B b5{A{0}};
// since-cxx11-error@-1 {{no matching constructor for initialization of 'B'}}
// since-cxx11-note@#dr1567-A-int {{candidate inherited constructor not viable: no known conversion from 'A' to 'int' for 1st argument}}
// since-cxx11-note@#dr1567-using-A {{constructor from base class 'A' inherited here}}
// since-cxx11-note@#dr1567-B {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'A' to 'const B' for 1st argument}}
// since-cxx11-note@#dr1567-B {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'A' to 'B' for 1st argument}}
// since-cxx11-note@#dr1567-B-double {{candidate constructor not viable: no known conversion from 'A' to 'double' for 1st argument}}
#endif
}

namespace dr1573 { // dr1573: 3.9
#if __cplusplus >= 201103L
// ellipsis is inherited (p0136r1 supersedes this part).
Expand Down
17 changes: 17 additions & 0 deletions clang/test/CXX/drs/dr17xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@ S s(q); // #dr1736-s
#endif
}

namespace dr1738 { // dr1738: sup P0136R1
#if __cplusplus >= 201103L
struct A {
template <typename T>
A(int, T) {}
};

struct B : A {
using A::A;
};

// FIXME: this is well-formed since P0136R1
template B::B(int, double);
// since-cxx11-error@-1 {{explicit instantiation of 'B' does not refer to a function template, variable template, member function, member class, or static data member}}
#endif
}

// dr1748 is in dr1748.cpp

namespace dr1753 { // dr1753: 11
Expand Down
41 changes: 41 additions & 0 deletions clang/test/CXX/drs/dr22xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,47 @@ const D &d3(c); // FIXME ill-formed
#endif
}

namespace dr2273 { // dr2273: 3.3
#if __cplusplus >= 201103L
struct A {
A(int = 0) = delete; // #dr2273-A
};

struct B : A { // #dr2273-B
using A::A;
};

B b;
// since-cxx11-error@-1 {{call to implicitly-deleted default constructor of 'B'}}
// since-cxx11-note@#dr2273-B {{default constructor of 'B' is implicitly deleted because base class 'A' has a deleted default constructor}}
// since-cxx11-note@#dr2273-A {{'A' has been explicitly marked deleted here}}
#endif
}

namespace dr2277 { // dr2277: partial
#if __cplusplus >= 201103L
struct A {
A(int, int = 0);
void f(int, int = 0); // #dr2277-A-f
};
struct B : A {
B(int);
using A::A;

void f(int); // #dr2277-B-f
using A::f;
};

void g() {
B b{0};
b.f(0); // FIXME: this is well-formed for the same reason as initialization of 'b' above
// since-cxx11-error@-1 {{call to member function 'f' is ambiguous}}
// since-cxx11-note@#dr2277-A-f {{candidate function}}
// since-cxx11-note@#dr2277-B-f {{candidate function}}
}
#endif
}

namespace dr2292 { // dr2292: 9
#if __cplusplus >= 201103L
template<typename T> using id = T;
Expand Down
25 changes: 25 additions & 0 deletions clang/test/CXX/drs/dr23xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,31 @@ enum struct alignas(64) B {};
#endif
} // namespace dr2354

namespace dr2356 { // dr2356: 4
#if __cplusplus >= 201103L
struct A {
A();
A(A &&); // #1
template<typename T> A(T &&); // #2
};
struct B : A {
using A::A;
B(const B &); // #3
B(B &&) = default; // #4, implicitly deleted
// since-cxx11-warning@-1 {{explicitly defaulted move constructor is implicitly deleted}}
// since-cxx11-note@#dr2356-X {{move constructor of 'B' is implicitly deleted because field 'x' has a deleted move constructor}}
// since-cxx11-note@#dr2356-X {{'X' has been explicitly marked deleted here}}
// since-cxx11-note@-4 {{replace 'default' with 'delete'}}

struct X { X(X &&) = delete; } x; // #dr2356-X
};
extern B b1;
B b2 = static_cast<B&&>(b1); // calls #3: #1, #2, and #4 are not viable
struct C { operator B&&(); };
B b3 = C(); // calls #3
#endif
}

#if __cplusplus >= 201402L
namespace dr2358 { // dr2358: 16
void f2() {
Expand Down
37 changes: 37 additions & 0 deletions clang/test/CXX/drs/dr2504.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK
// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK,SINCE-CXX11
// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK,SINCE-CXX11

namespace dr2504 { // dr2504: no
#if __cplusplus >= 201103L
struct V { V() = default; V(int); };
struct Q { Q(); };
struct A : virtual V, Q {
using V::V;
A() = delete;
};
int bar() { return 42; }
struct B : A {
B() : A(bar()) {} // ok
};
struct C : B {};
void foo() { C c; } // bar is not invoked, because the V subobject is not initialized as part of B
#endif
}

// FIXME: As specified in the comment above (which comes from an example in the Standard),
// we are not supposed to unconditionally call `bar()` and call a constructor
// inherited from `V`.

// SINCE-CXX11-LABEL: define linkonce_odr void @dr2504::B::B()
// SINCE-CXX11-NOT: br
// SINCE-CXX11: call noundef i32 @dr2504::bar()
// SINCE-CXX11-NOT: br
// SINCE-CXX11: call void @dr2504::A::A(int)
// SINCE-CXX11-LABEL: }

// CHECK: {{.*}}
2 changes: 2 additions & 0 deletions clang/test/CXX/drs/dr25xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
// expected-no-diagnostics
#endif

// dr2504 is in dr2504.cpp

namespace dr2516 { // dr2516: 3.0
// NB: reusing 1482 test
#if __cplusplus >= 201103L
Expand Down
16 changes: 8 additions & 8 deletions clang/www/cxx_dr_status.html
Original file line number Diff line number Diff line change
Expand Up @@ -6708,7 +6708,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://cplusplus.github.io/CWG/issues/1150.html">1150</a></td>
<td>NAD</td>
<td>Inheriting constructors have not been implemented</td>
<td class="unknown" align="center">Unknown</td>
<td class="na" align="center">N/A</td>
</tr>
<tr id="1151">
<td><a href="https://cplusplus.github.io/CWG/issues/1151.html">1151</a></td>
Expand Down Expand Up @@ -8730,7 +8730,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://cplusplus.github.io/CWG/issues/1487.html">1487</a></td>
<td>CD3</td>
<td>When are inheriting constructors declared?</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Clang 3.3</td>
</tr>
<tr class="open" id="1488">
<td><a href="https://cplusplus.github.io/CWG/issues/1488.html">1488</a></td>
Expand Down Expand Up @@ -9210,7 +9210,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://cplusplus.github.io/CWG/issues/1567.html">1567</a></td>
<td>C++14</td>
<td>Inheriting constructors and copy/move constructors</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Clang 3.3</td>
</tr>
<tr id="1568">
<td><a href="https://cplusplus.github.io/CWG/issues/1568.html">1568</a></td>
Expand Down Expand Up @@ -10236,7 +10236,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://cplusplus.github.io/CWG/issues/1738.html">1738</a></td>
<td>C++14</td>
<td>Explicit instantiation/specialization of inheriting constructor templates</td>
<td class="unknown" align="center">Unknown</td>
<td class="na" align="center">Superseded by <a href="https://wg21.link/P0136R1">P0136R1</a></td>
</tr>
<tr id="1739">
<td><a href="https://cplusplus.github.io/CWG/issues/1739.html">1739</a></td>
Expand Down Expand Up @@ -13446,7 +13446,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://cplusplus.github.io/CWG/issues/2273.html">2273</a></td>
<td>CD5</td>
<td>Inheriting constructors vs implicit default constructor</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Clang 3.3</td>
</tr>
<tr id="2274">
<td><a href="https://cplusplus.github.io/CWG/issues/2274.html">2274</a></td>
Expand All @@ -13470,7 +13470,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://cplusplus.github.io/CWG/issues/2277.html">2277</a></td>
<td>CD5</td>
<td>Ambiguity inheriting constructors with default arguments</td>
<td class="unknown" align="center">Unknown</td>
<td class="partial" align="center">Partial</td>
</tr>
<tr id="2278">
<td><a href="https://cplusplus.github.io/CWG/issues/2278.html">2278</a></td>
Expand Down Expand Up @@ -13944,7 +13944,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://cplusplus.github.io/CWG/issues/2356.html">2356</a></td>
<td>CD5</td>
<td>Base class copy and move constructors should not be inherited</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Clang 4</td>
</tr>
<tr id="2357">
<td><a href="https://cplusplus.github.io/CWG/issues/2357.html">2357</a></td>
Expand Down Expand Up @@ -14832,7 +14832,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
<td><a href="https://cplusplus.github.io/CWG/issues/2504.html">2504</a></td>
<td>DR</td>
<td>Inheriting constructors from virtual base classes</td>
<td class="unknown" align="center">Unknown</td>
<td class="none" align="center">No</td>
</tr>
<tr class="open" id="2505">
<td><a href="https://cplusplus.github.io/CWG/issues/2505.html">2505</a></td>
Expand Down

0 comments on commit 50c5107

Please sign in to comment.