Home | History | Annotate | Download | only in SemaCXX
      1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
      2 
      3 template <class T>
      4 struct only
      5 {
      6     only(T) {}
      7 
      8     template <class U>
      9     only(U)
     10     {
     11         static_assert(sizeof(U) == 0, "expected type failure");
     12     }
     13 };
     14 
     15 auto f() -> int
     16 {
     17     return 0;
     18 }
     19 
     20 auto g(); // expected-error{{return without trailing return type}}
     21 
     22 int h() -> int; // expected-error{{trailing return type must specify return type 'auto', not 'int'}}
     23 
     24 int x;
     25 
     26 template <class T>
     27 auto i(T x) -> decltype(x)
     28 {
     29     return x;
     30 }
     31 
     32 only<double> p1 = i(1.0);
     33 
     34 template <class T>
     35 struct X
     36 {
     37     auto f(T x) -> T { return x; }
     38 
     39     template <class U>
     40     auto g(T x, U y) -> decltype(x + y)
     41     {
     42         return x + y;
     43     }
     44 
     45   template<typename U>
     46   struct nested {
     47     template <class V>
     48     auto h(T x, U y, V z) -> decltype(x + y + z)
     49     {
     50         return x + y + z;
     51     }
     52   };
     53 
     54   template<typename U>
     55   nested<U> get_nested();
     56 };
     57 
     58 X<int> xx;
     59 only<int> p2 = xx.f(0L);
     60 only<double> p3 = xx.g(0L, 1.0);
     61 only<double> p4 = xx.get_nested<double>().h(0L, 1.0, 3.14f);
     62