Debian Codegraph @

gcc/testsuite/g++.dg/template/explicit-args6.C

raw
1 // PR c++/101460
2 // { dg-do compile { target c++11 } }
3
4 template<bool> struct enable_if { };
5 template<> struct enable_if<true> { using type = void; };
6
7 template<bool B>
8 using enable_if_t = typename enable_if<B>::type;
9
10 struct tuple { };
11 struct pair { };
12
13 template<unsigned N> enable_if_t<N == 1> get(tuple&) { } // { dg-bogus "candidate" }
14 template<unsigned N> enable_if_t<N == 1> get(const tuple&) { } // { dg-bogus "candidate" }
15 template<unsigned N> enable_if_t<N == 1> get(pair&) { } // { dg-bogus "candidate" }
16 template<unsigned N> enable_if_t<N == 1> get(const pair&) { } // { dg-bogus "candidate" }
17
18 template<int N>
19 constexpr unsigned
20 frob()
21 {
22 static_assert(N == 1, "user-friendly diagnostic"); // { dg-error "user-friendly" }
23 // { dg-message "-1 == 1" "" { target *-*-* } .-1 }
24
25 // narrowing check, reject negative values
26 return unsigned{N}; // { dg-prune-output "narrowing" }
27 }
28
29 // This complains about calling frob only in C++11 because
30 // maybe_save_constexpr_fundef fails; in later standards it succeeds,
31 // and the evaluation failure is silent due to the earlier errors.
32 template<int N> void get_n(tuple& t) { get<frob<N>()>(t); } // { dg-error "" "" { target c++11_only } }
33
34 int main()
35 {
36 tuple t;
37 get_n<-1>(t);
38 }