brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · cf973d2 Raw
95 lines · cpp
1// RUN: %clang_cc1 -std=c++1z -verify %s2 3struct A {4  A() {}5  A(int) : A() {} // ok6 7  virtual void f() = 0; // expected-note 1+{{unimplemented}}8};9 10template<typename> struct SecretlyAbstract {11  SecretlyAbstract();12  SecretlyAbstract(int);13  virtual void f() = 0; // expected-note 1+{{unimplemented}}14};15using B = SecretlyAbstract<int>;16using C = SecretlyAbstract<float>;17using D = SecretlyAbstract<char>[1];18 19B b; // expected-error {{abstract class}}20D d; // expected-error {{abstract class}}21 22template<int> struct N{};23 24// Note: C is not instantiated anywhere in this file, so we never discover that25// it is in fact abstract. The C++ standard suggests that we need to26// instantiate in all cases where abstractness could affect the validity of a27// program, but that breaks a *lot* of code, so we don't do that.28//29// FIXME: Once DR1640 is resolved, remove the check on forming an abstract30// array type entirely. The only restriction we need is that you can't create31// an object of abstract (most-derived) type.32 33 34// An abstract class shall not be used35 36//  - as a parameter type37void f(A&);38void f(A){} // expected-error {{abstract class}}39void f(A[1]){} // expected-error {{abstract class}}40void f(B){} // expected-error {{abstract class}}41void f(B[1]){} // expected-error {{abstract class}}42void f(C);43void f(C[1]);44void f(D){} // expected-error {{abstract class}}45void f(D[1]){} // expected-error {{abstract class}}46 47//  - as a function return type48A &f(N<0>);49A *f(N<1>);50A f(N<2>){} // expected-error {{abstract class}}51A (&f(N<3>))[2]; // expected-error {{abstract class}}52B f(N<4>){} // expected-error {{abstract class}}53B (&f(N<5>))[2]; // expected-error {{abstract class}}54C f(N<6>);55C (&f(N<7>))[2];56 57//  - as the type of an explicit conversion58void g(A&&);59void h() {60  A(); // expected-error {{abstract class}}61  A(0); // expected-error {{abstract class}}62  A{}; // expected-error {{abstract class}}63  A{0}; // expected-error {{abstract class}}64  (A)(0); // expected-error {{abstract class}}65  (A){}; // expected-error {{abstract class}}66  (A){0}; // expected-error {{abstract class}}67 68  D(); // expected-error {{array type}}69  D{}; // expected-error {{abstract class}}70  D{0}; // expected-error {{abstract class}}71  (D){}; // expected-error {{abstract class}}72  (D){0}; // expected-error {{abstract class}}73}74 75template<typename T> void t(T);76void i(A &a, B &b, C &c, D &d) {77  t(a); // expected-error {{allocating an object of abstract class type 'A'}}78  t(b); // expected-error {{allocating an object of abstract class type 'SecretlyAbstract<int>'}}79  t(c); // expected-error {{allocating an object of abstract class type}}80  t(d); // ok, decays to pointer81}82 83struct E : A {84  E() : A() {} // ok85  E(int n) : A( A(n) ) {} // expected-error {{abstract class}}86};87 88namespace std {89  template<typename T> struct initializer_list {90    const T *begin, *end;91    initializer_list();92  };93}94std::initializer_list<A> ila = {1, 2, 3, 4}; // expected-error {{abstract class}}95