p2.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wno-unused-value %s -verify
  2. // prvalue
  3. void prvalue() {
  4. auto&& x = []()->void { };
  5. auto& y = []()->void { }; // expected-error{{cannot bind to a temporary of type}}
  6. }
  7. namespace std {
  8. class type_info;
  9. }
  10. struct P {
  11. virtual ~P();
  12. };
  13. void unevaluated_operand(P &p, int i) {
  14. int i2 = sizeof([] ()->int { return 0; }()); // expected-error{{lambda expression in an unevaluated operand}}
  15. const std::type_info &ti1 = typeid([&]() -> P& { return p; }());
  16. const std::type_info &ti2 = typeid([&]() -> int { return i; }()); // expected-error{{lambda expression in an unevaluated operand}}
  17. }
  18. template<typename T>
  19. struct Boom {
  20. Boom(const Boom&) {
  21. T* x = 1; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} \
  22. // expected-error{{cannot initialize a variable of type 'double *' with an rvalue of type 'int'}}
  23. }
  24. void tickle() const;
  25. };
  26. void odr_used(P &p, Boom<int> boom_int, Boom<float> boom_float,
  27. Boom<double> boom_double) {
  28. const std::type_info &ti1
  29. = typeid([=,&p]() -> P& { boom_int.tickle(); return p; }()); // expected-note{{in instantiation of member function 'Boom<int>::Boom' requested here}}
  30. // This does not cause the instantiation of the Boom copy constructor,
  31. // because the copy-initialization of the capture of boom_float occurs in an
  32. // unevaluated operand.
  33. const std::type_info &ti2
  34. = typeid([=]() -> int { boom_float.tickle(); return 0; }()); // expected-error{{lambda expression in an unevaluated operand}}
  35. auto foo = [=]() -> int { boom_double.tickle(); return 0; }; // expected-note{{in instantiation of member function 'Boom<double>::Boom' requested here}}
  36. }