1// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4// RUN: %clang_cc1 -std=c++1z -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5
6#if __cplusplus < 201103L
7// expected-no-diagnostics
8#endif
9
10namespace dr1550 { // dr1550: yes
11  int f(bool b, int n) {
12    return (b ? (throw 0) : n) + (b ? n : (throw 0));
13  }
14}
15
16namespace dr1560 { // dr1560: 3.5
17  void f(bool b, int n) {
18    (b ? throw 0 : n) = (b ? n : throw 0) = 0;
19  }
20  class X { X(const X&); };
21  const X &get();
22  const X &x = true ? get() : throw 0;
23}
24
25#if __cplusplus >= 201103L
26namespace std {
27  typedef decltype(sizeof(int)) size_t;
28
29  // libc++'s implementation
30  template <class _E>
31  class initializer_list
32  {
33    const _E* __begin_;
34    size_t    __size_;
35
36    initializer_list(const _E* __b, size_t __s)
37    : __begin_(__b), __size_(__s) {}
38
39  public:
40    typedef _E        value_type;
41    typedef const _E& reference;
42    typedef const _E& const_reference;
43    typedef size_t    size_type;
44
45    typedef const _E* iterator;
46    typedef const _E* const_iterator;
47
48    initializer_list() : __begin_(nullptr), __size_(0) {}
49
50    size_t    size()  const {return __size_;}
51    const _E* begin() const {return __begin_;}
52    const _E* end()   const {return __begin_ + __size_;}
53  };
54
55  template < class _T1, class _T2 > struct pair { _T2 second; };
56
57  template<typename T> struct basic_string {
58    basic_string(const T* x) {}
59    ~basic_string() {};
60  };
61  typedef basic_string<char> string;
62
63} // std
64
65namespace dr1589 {   // dr1589: 3.7 c++11
66  // Ambiguous ranking of list-initialization sequences
67
68  void f0(long, int=0);                 // Would makes selection of #0 ambiguous
69  void f0(long);                        // #0
70  void f0(std::initializer_list<int>);  // #00
71  void g0() { f0({1L}); }               // chooses #00
72
73  void f1(int, int=0);                    // Would make selection of #1 ambiguous
74  void f1(int);                           // #1
75  void f1(std::initializer_list<long>);   // #2
76  void g1() { f1({42}); }                 // chooses #2
77
78  void f2(std::pair<const char*, const char*>, int = 0); // Would makes selection of #3 ambiguous
79  void f2(std::pair<const char*, const char*>); // #3
80  void f2(std::initializer_list<std::string>);  // #4
81  void g2() { f2({"foo","bar"}); }              // chooses #4
82
83  namespace with_error {
84    void f0(long);                        // #0    expected-note {{candidate function}}
85    void f0(std::initializer_list<int>);  // #00   expected-note {{candidate function}}
86    void f0(std::initializer_list<int>, int = 0);  // Makes selection of #00 ambiguous \
87    // expected-note {{candidate function}}
88    void g0() { f0({1L}); }                 // chooses #00    expected-error{{call to 'f0' is ambiguous}}
89
90    void f1(int);                           // #1   expected-note {{candidate function}}
91    void f1(std::initializer_list<long>);   // #2   expected-note {{candidate function}}
92    void f1(std::initializer_list<long>, int = 0);   // Makes selection of #00 ambiguous \
93    // expected-note {{candidate function}}
94    void g1() { f1({42}); }                 // chooses #2   expected-error{{call to 'f1' is ambiguous}}
95
96    void f2(std::pair<const char*, const char*>); // #3   TODO: expected- note {{candidate function}}
97    void f2(std::initializer_list<std::string>);  // #4   expected-note {{candidate function}}
98    void f2(std::initializer_list<std::string>, int = 0);   // Makes selection of #00 ambiguous \
99    // expected-note {{candidate function}}
100    void g2() { f2({"foo","bar"}); }        // chooses #4   expected-error{{call to 'f2' is ambiguous}}
101  }
102
103} // dr1589
104#endif
105