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 10 namespace dr1550 { // dr1550: yes f(bool b,int n)11 int f(bool b, int n) { 12 return (b ? (throw 0) : n) + (b ? n : (throw 0)); 13 } 14 } 15 16 namespace dr1560 { // dr1560: 3.5 f(bool b,int n)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 26 namespace 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 initializer_list(const _E * __b,size_t __s)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 initializer_list()48 initializer_list() : __begin_(nullptr), __size_(0) {} 49 size() const50 size_t size() const {return __size_;} begin() const51 const _E* begin() const {return __begin_;} end() const52 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 { basic_stringstd::basic_string58 basic_string(const T* x) {} ~basic_stringstd::basic_string59 ~basic_string() {}; 60 }; 61 typedef basic_string<char> string; 62 63 } // std 64 65 namespace 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 g0()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 g1()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 g2()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}} g0()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}} g1()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}} g2()100 void g2() { f2({"foo","bar"}); } // chooses #4 expected-error{{call to 'f2' is ambiguous}} 101 } 102 103 } // dr1589 104 #endif 105