1 // { dg-do compile { target c++14 } } 2 // { dg-options "-Wno-return-local-addr" } 3 4 template<class,class> struct same_type; 5 template<class T> struct same_type<T,T> {}; 6 7 int& f(); 8 int i; 9 10 decltype(auto) g() { return f(); } 11 decltype(auto) h1() { return i; } 12 decltype(auto) h2() { return (i); } 13 decltype(auto) h2a() { return 0,i; } 14 15 struct A { int i; }; 16 A a; 17 18 decltype(auto) h3() { return a.i; } 19 decltype(auto) h4() { return (a.i); } 20 21 template <class T> 22 decltype(auto) h5(T t) { return t.i; } 23 template <class T> 24 decltype(auto) h6(T t) { return (t.i); } 25 template <class T> 26 decltype(auto) h7(T t) { return (i); } 27 28 int main() 29 { 30 decltype(auto) i = f(); 31 same_type<decltype(i),int&>(); 32 decltype(auto) i2 = i; 33 same_type<decltype(i2),int&>(); 34 decltype(auto) i3 = ::i; 35 same_type<decltype(i3),int>(); 36 decltype(auto) i4 = (::i); 37 same_type<decltype(i4),int&>(); 38 decltype(auto) i5 = a.i; 39 same_type<decltype(i5),int>(); 40 decltype(auto) i6 = (a.i); 41 same_type<decltype(i6),int&>(); 42 decltype(auto) i7 = true ? ::i : ::i; 43 same_type<decltype(i7),int&>(); 44 45 same_type<decltype(g()),int&>(); 46 same_type<decltype(h1()),int>(); 47 same_type<decltype(h2()),int&>(); 48 same_type<decltype(h2a()),int&>(); 49 same_type<decltype(h3()),int>(); 50 same_type<decltype(h4()),int&>(); 51 same_type<decltype(h5(a)),int>(); 52 same_type<decltype(h6(a)),int&>(); 53 same_type<decltype(h7(a)),int&>(); 54 } 55