xref: /llvm-project/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p2.cpp (revision c38498f0469aba6a0fb63d99ad398cdf788c5696)
16c93b3e2SAaron Ballman // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wno-unused-value %s -verify
289625491SDouglas Gregor 
389625491SDouglas Gregor // prvalue
prvalue()489625491SDouglas Gregor void prvalue() {
5656bc62aSDouglas Gregor   auto&& x = []()->void { };
6656bc62aSDouglas Gregor   auto& y = []()->void { }; // expected-error{{cannot bind to a temporary of type}}
789625491SDouglas Gregor }
889625491SDouglas Gregor 
989625491SDouglas Gregor namespace std {
1089625491SDouglas Gregor   class type_info;
1189625491SDouglas Gregor }
1289625491SDouglas Gregor 
1389625491SDouglas Gregor struct P {
1489625491SDouglas Gregor   virtual ~P();
1589625491SDouglas Gregor };
1689625491SDouglas Gregor 
unevaluated_operand(P & p,int i)1789625491SDouglas Gregor void unevaluated_operand(P &p, int i) {
184e28b265SEli Friedman   int i2 = sizeof([] ()->int { return 0; }()); // expected-error{{lambda expression in an unevaluated operand}}
19656bc62aSDouglas Gregor   const std::type_info &ti1 = typeid([&]() -> P& { return p; }());
20656bc62aSDouglas Gregor   const std::type_info &ti2 = typeid([&]() -> int { return i; }());  // expected-error{{lambda expression in an unevaluated operand}}
2189625491SDouglas Gregor }
2289625491SDouglas Gregor 
2389625491SDouglas Gregor template<typename T>
2489625491SDouglas Gregor struct Boom {
BoomBoom2589625491SDouglas Gregor   Boom(const Boom&) {
2689625491SDouglas Gregor     T* x = 1; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} \
2789625491SDouglas Gregor     // expected-error{{cannot initialize a variable of type 'double *' with an rvalue of type 'int'}}
2889625491SDouglas Gregor   }
2989625491SDouglas Gregor   void tickle() const;
3089625491SDouglas Gregor };
3189625491SDouglas Gregor 
odr_used(P & p,Boom<int> boom_int,Boom<float> boom_float,Boom<double> boom_double)3289625491SDouglas Gregor void odr_used(P &p, Boom<int> boom_int, Boom<float> boom_float,
3389625491SDouglas Gregor               Boom<double> boom_double) {
3489625491SDouglas Gregor   const std::type_info &ti1
35656bc62aSDouglas Gregor     = typeid([=,&p]() -> P& { boom_int.tickle(); return p; }()); // expected-note{{in instantiation of member function 'Boom<int>::Boom' requested here}}
36*c38498f0SRichard Smith   // This does not cause the instantiation of the Boom copy constructor,
37*c38498f0SRichard Smith   // because the copy-initialization of the capture of boom_float occurs in an
38*c38498f0SRichard Smith   // unevaluated operand.
3989625491SDouglas Gregor   const std::type_info &ti2
40*c38498f0SRichard Smith     = typeid([=]() -> int { boom_float.tickle(); return 0; }()); // expected-error{{lambda expression in an unevaluated operand}}
4189625491SDouglas Gregor 
42656bc62aSDouglas Gregor   auto foo = [=]() -> int { boom_double.tickle(); return 0; }; // expected-note{{in instantiation of member function 'Boom<double>::Boom' requested here}}
4389625491SDouglas Gregor }
44