Debian Codegraph @

gcc/testsuite/g++.dg/cpp1z/constexpr-if39.C

raw
1 // PR c++/120555
2 // { dg-do compile { target c++17 } }
3
4 struct A { int m; };
5
6 template<class T>
7 constexpr auto f() {
8 if constexpr (sizeof(T) == sizeof(int))
9 return 1;
10 else
11 return A{f<int>()};
12 }
13
14 static_assert(f<bool>().m == 1);
15 static_assert(f<int>() == 1);
16
17 template <class T> constexpr auto g();
18
19 template<class T>
20 constexpr auto f2() {
21 if constexpr (sizeof(T) == sizeof(int))
22 return 1;
23 else
24 return A{g<int>()}; // { dg-error "auto" }
25 }
26
27 template <class T> constexpr auto g() { return A{1}; }
28
29 static_assert(f2<bool>().m == 1);
30 static_assert(f2<int>() == 1);