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; deduced return types are a C++14 extension}}
     21 decltype(auto) g2(); // expected-warning{{extension}} expected-error-re{{{{^}}deduced return types are a C++14 extension}}
     22 auto badness = g2();
     23 
     24 int h() -> int; // expected-error{{trailing return type must specify return type 'auto', not 'int'}}
     25 
     26 int i();
     27 auto i() -> int;
     28 int i() {}
     29 
     30 using T = auto (int) -> auto (*)(char) -> void; // expected-note {{previous}}
     31 using T = void; // expected-error {{type alias redefinition with different types ('void' vs 'auto (int) -> auto (*)(char) -> void')}}
     32 
     33 using U = auto (int) -> auto (*)(char) -> void;
     34 using U = void (*(int))(char); // ok
     35 
     36 int x;
     37 
     38 template <class T>
     39 auto i(T x) -> decltype(x)
     40 {
     41     return x;
     42 }
     43 
     44 only<double> p1 = i(1.0);
     45 
     46 template <class T>
     47 struct X
     48 {
     49     auto f(T x) -> T { return x; }
     50 
     51     template <class U>
     52     auto g(T x, U y) -> decltype(x + y)
     53     {
     54         return x + y;
     55     }
     56 
     57   template<typename U>
     58   struct nested {
     59     template <class V>
     60     auto h(T x, U y, V z) -> decltype(x + y + z)
     61     {
     62         return x + y + z;
     63     }
     64   };
     65 
     66   template<typename U>
     67   nested<U> get_nested();
     68 };
     69 
     70 X<int> xx;
     71 only<int> p2 = xx.f(0L);
     72 only<double> p3 = xx.g(0L, 1.0);
     73 only<double> p4 = xx.get_nested<double>().h(0L, 1.0, 3.14f);
     74 
     75 namespace PR12053 {
     76   template <typename T>
     77   auto f1(T t) -> decltype(f1(t)) {} // expected-note{{candidate template ignored}}
     78 
     79   void test_f1() {
     80     f1(0); // expected-error{{no matching function for call to 'f1'}}
     81   }
     82 
     83   template <typename T>
     84   auto f2(T t) -> decltype(f2(&t)) {} // expected-note{{candidate template ignored}}
     85 
     86   void test_f2() {
     87     f2(0); // expected-error{{no matching function for call to 'f2'}}
     88   }
     89 }
     90 
     91 namespace DR1608 {
     92   struct S {
     93     void operator+();
     94     int operator[](int);
     95     auto f() -> decltype(+*this); // expected-note {{here}}
     96     auto f() -> decltype((*this)[0]); // expected-error {{cannot be overloaded}}
     97   };
     98 }
     99 
    100 namespace PR16273 {
    101   struct A {
    102     template <int N> void f();
    103     auto g()->decltype(this->f<0>());
    104   };
    105 }
    106 
    107