brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · 8350eac Raw
114 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s2 3struct A { };4A::A() { } // expected-error {{definition of implicitly declared default constructor}}5 6struct B { };7B::B(const B&) { } // expected-error {{definition of implicitly declared copy constructor}}8 9struct C { };10C& C::operator=(const C&) { return *this; } // expected-error {{definition of implicitly declared copy assignment operator}}11 12struct D { };13D::~D() { } // expected-error {{definition of implicitly declared destructor}}14 15// Make sure that the special member functions are introduced for16// name-lookup purposes and overload with user-declared17// constructors and assignment operators.18namespace PR6570 {19  class A { };20 21  class B {22  public:23    B() {}24 25    B(const A& a) {26      operator = (CONST);27      operator = (a);28    }29 30    B& operator = (const A& a) {31      return *this;32    }33 34    void f(const A &a) {35      B b(a);36    };37 38    static const B CONST;39  };40 41}42 43namespace PR7594 {44  // If the lazy declaration of special member functions is triggered45  // in an out-of-line initializer, make sure the functions aren't in46  // the initializer scope. This used to crash Clang:47  struct C {48    C();49    static C *c;50  };51  C *C::c = new C();52}53 54namespace Recursion {55  template<typename T> struct InvokeCopyConstructor {56    static const T &get();57    typedef decltype(T(get())) type;58  };59  struct B;60  struct A {61    typedef B type;62    template<typename T,63             typename = typename InvokeCopyConstructor<typename T::type>::type>64    A(const T &);65  };66  struct B {67    B();68    A a;69  };70  // Triggering the declaration of B's copy constructor causes overload71  // resolution to occur for A's copying constructor, which picks72  // the implicit copy constructor of A.73  // Because that copy constructor is always a perfect match the template74  // candidate is not instantiated.75  B b = B();76 77 78  // Another case, which isn't ill-formed under our rules. This is inspired by79  // a problem which occurs when combining CGAL with libstdc++-4.7.80 81  template<typename T> T &&declval();82  template<typename T, typename U> struct pair {83    pair();84    template<typename V, typename W,85             typename = decltype(T(declval<const V&>())),86             typename = decltype(U(declval<const W&>()))>87    pair(const pair<V,W> &);88  };89 90  template<typename K> struct Line;91 92  template<typename K> struct Vector {93    Vector(const Line<K> &l);94  };95 96  template<typename K> struct Point {97    Vector<K> v;98  };99 100  template<typename K> struct Line {101    pair<Point<K>, Vector<K>> x;102  };103 104  // Trigger declaration of Line copy ctor, which causes substitution into105  // pair's templated constructor, which triggers instantiation of the106  // definition of Point's copy constructor, which performs overload resolution107  // on Vector's constructors, which requires declaring all of Line's108  // constructors. That should not find a copy constructor (because we've not109  // declared it yet), but by the time we get all the way back here, we should110  // find the copy constructor.111  Line<void> L1;112  Line<void> L2(L1);113}114