From c1789eb62222b9170c7ec6c38a21586c94132a4b Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 3 Feb 2014 01:23:27 +0000 Subject: [PATCH] Tests for DR301-320. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200671 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CXX/drs/dr3xx.cpp | 221 ++++++++++++++++++++++++++++++++++++++++- www/cxx_dr_status.html | 36 +++---- 2 files changed, 238 insertions(+), 19 deletions(-) diff --git a/test/CXX/drs/dr3xx.cpp b/test/CXX/drs/dr3xx.cpp index c9b1fe7733..be8b3c4e05 100644 --- a/test/CXX/drs/dr3xx.cpp +++ b/test/CXX/drs/dr3xx.cpp @@ -8,7 +8,7 @@ namespace dr300 { // dr300: yes void h() { f(g); } } -namespace dr301 { // dr301 WIP +namespace dr301 { // dr301: yes // see also dr38 struct S; template void operator+(T, T); @@ -33,4 +33,223 @@ namespace dr301 { // dr301 WIP T::template operator+::foobar(); // expected-error {{qualified name refers into a specialization of function template 'T::template operator +'}} T::template operator+(0); // ok } + + template class operator& {}; // expected-error +{{}} + template class T::operator& {}; // expected-error +{{}} + template class S::operator& {}; // expected-error +{{}} +} + +namespace dr302 { // dr302: yes + struct A { A(); ~A(); }; +#if __cplusplus < 201103L + struct B { // expected-error {{implicit default constructor for 'dr302::B' must explicitly initialize the const member 'n'}} + const int n; // expected-note {{declared here}} + A a; + } b = B(); // expected-note {{first required here}} + // Trivial default constructor C::C() is not called here. + struct C { + const int n; + } c = C(); +#else + struct B { + const int n; // expected-note {{deleted because field 'n' of const-qualified type 'const int' would not be initialized}} + A a; + } b = B(); // expected-error {{call to implicitly-deleted default constructor}} + // C::C() is called here, because even though it's trivial, it's deleted. + struct C { + const int n; // expected-note {{deleted because field 'n' of const-qualified type 'const int' would not be initialized}} + } c = C(); // expected-error {{call to implicitly-deleted default constructor}} + struct D { + const int n = 0; + } d = D(); +#endif +} + +// dr303: na + +namespace dr304 { // dr304: yes + typedef int &a; + int n = a(); // expected-error {{requires an initializer}} + + struct S { int &b; }; + int m = S().b; +#if __cplusplus < 201103L + // expected-error@-3 {{requires an initializer}} + // expected-note@-3 {{in value-initialization}} +#else + // expected-error@-5 {{deleted}} + // expected-note@-7 {{reference}} +#endif +} + +namespace dr305 { // dr305: yes + struct A { + typedef A C; + }; + void f(A *a) { + struct A {}; + a->~A(); + a->~C(); + } + typedef A B; + void g(B *b) { + b->~B(); + b->~C(); + } + void h(B *b) { + struct B {}; // expected-note {{declared here}} + b->~B(); // expected-error {{does not match}} + } + + template struct X {}; + void i(X* x) { + struct X {}; + x->~X(); + x->~X(); + x->~X(); // expected-error {{no member named}} + } + +#if __cplusplus >= 201103L + struct Y { + template using T1 = Y; + }; + template using T2 = Y; + void j(Y *y) { + y->~T1(); + y->~T2(); + } + struct Z { + template using T2 = T; + }; + void k(Z *z) { + // FIXME: This diagnostic is terrible. + z->~T1(); // expected-error {{'T1' following the 'template' keyword does not refer to a template}} expected-error +{{}} + z->~T2(); // expected-error {{no member named '~int'}} + z->~T2(); + } +#endif +} + +namespace dr306 { // dr306: no + // FIXME: dup 39 + // FIXME: This should be accepted. + struct A { struct B {}; }; // expected-note 2{{member}} + struct C { typedef A::B B; }; // expected-note {{member}} + struct D : A, A::B, C {}; + D::B b; // expected-error {{found in multiple base classes of different types}} +} + +// dr307: na + +namespace dr308 { // dr308: yes + // This is mostly an ABI library issue. + struct A {}; + struct B : A {}; + struct C : A {}; + struct D : B, C {}; + void f() { + try { + throw D(); + } catch (const A&) { + // unreachable + } catch (const B&) { + // get here instead + } + } +} + +// dr309: dup 485 + +namespace dr311 { // dr311: yes + namespace X { namespace Y {} } + namespace X::Y {} // expected-error {{must define each namespace separately}} + namespace X { + namespace X::Y {} // expected-error {{must define each namespace separately}} + } + // FIXME: The diagnostics here are not very good. + namespace ::dr311::X {} // expected-error 2+{{}} // expected-warning {{extra qual}} +} + +// dr312: dup 616 + +namespace dr313 { // dr313: dup 299 c++11 + struct A { operator int() const; }; + int *p = new int[A()]; +#if __cplusplus < 201103L + // FIXME: should this be available in c++98 mode? expected-error@-2 {{extension}} +#endif +} + +// dr315: na +// dr316: sup 1004 + +namespace dr317 { // dr317: no + void f() {} + inline void f(); // FIXME: ill-formed + + int g(); + int n = g(); + inline int g() { return 0; } + + int h(); + int m = h(); + int h() { return 0; } + inline int h(); // FIXME: ill-formed +} + +namespace dr318 { // dr318: sup 1310 + struct A {}; + struct A::A a; +} + +namespace dr319 { // dr319: no + // FIXME: dup dr389 + // FIXME: We don't have a diagnostic for a name with linkage + // having a type without linkage. + typedef struct { + int i; + } *ps; + extern "C" void f(ps); + void g(ps); // FIXME: ill-formed, type 'ps' has no linkage + + static enum { e } a1; + enum { e2 } a2; // FIXME: ill-formed, enum type has no linkage + + enum { n1 = 1u }; + typedef int (*pa)[n1]; + pa parr; // ok, type has linkage despite using 'n1' + + template struct X {}; + + void f() { + struct A { int n; }; + extern A a; // FIXME: ill-formed + X xa; + + typedef A B; + extern B b; // FIXME: ill-formed + X xb; + + const int n = 1; + typedef int (*C)[n]; + extern C c; // ok + X xc; + } +#if __cplusplus < 201103L + // expected-error@-12 {{uses local type 'A'}} + // expected-error@-9 {{uses local type 'A'}} +#endif +} + +namespace dr320 { // dr320: yes +#if __cplusplus >= 201103L + struct X { + constexpr X() {} + constexpr X(const X &x) : copies(x.copies + 1) {} + unsigned copies = 0; + }; + constexpr X f(X x) { return x; } + constexpr unsigned g(X x) { return x.copies; } + static_assert(f(X()).copies == g(X()) + 1, "expected one extra copy for return value"); +#endif } diff --git a/www/cxx_dr_status.html b/www/cxx_dr_status.html index e2da255f13..a542e0cc22 100644 --- a/www/cxx_dr_status.html +++ b/www/cxx_dr_status.html @@ -1847,55 +1847,55 @@ of class templates 301 CD1 Syntax for template-name - Unknown + Yes 302 CD1 Value-initialization and generation of default constructor - Unknown + Yes 303 NAD Integral promotions on bit-fields - Unknown + N/A 304 TC1 Value-initialization of a reference - Unknown + Yes 305 CD1 Name lookup in destructor call - Unknown + Yes 306 CD1 Ambiguity by class name injection - Unknown + No 307 NAD Initialization of a virtual base class subobject - Unknown + N/A 308 NAD Catching exceptions with ambiguous base classes - Unknown + Yes 309 CD1 Linkage of entities whose names are not simply identifiers, in introduction - Unknown + Duplicate of 485 310 @@ -1907,19 +1907,19 @@ of class templates 311 NAD Using qualified name to reopen nested namespace - Unknown + Yes 312 DRWP “use” of invalid pointer value not defined - Unknown + Duplicate of 616 313 dup Class with single conversion function to integral as array size in new - Unknown + Duplicate of 299 (C++11 onwards) 314 @@ -1931,37 +1931,37 @@ of class templates 315 NAD Is call of static member function through null pointer undefined? - Unknown + N/A 316 NAD Injected-class-name of template used as template template parameter - Unknown + Superseded by 1004 317 CD1 Can a function be declared inline after it has been called? - Unknown + No 318 CD1 struct A::A should not name the constructor of A - Unknown + Superseded by 1310 319 CD1 Use of names without linkage in declaring entities with linkage - Unknown + No 320 CD1 Question on copy constructor elision example - Unknown + Yes 321 -- 2.40.0