brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 645a7ca Raw
60 lines · cpp
1// RUN: %clang_cc1 -verify -std=c++20 %s -fsyntax-only2 3namespace std {4template <class T> struct remove_reference { typedef T type; };5template <class T> struct remove_reference<T&> { typedef T type; };6template <class T> struct remove_reference<T&&> { typedef T type; };7 8template <class T> typename remove_reference<T>::type &&move(T &&t);9} // namespace std10 11// dcl.init 16.6.2.212struct A {13  int a;14  int&& r;15};16 17int f();18int n = 10;19 20A a1{1, f()}; // OK, lifetime is extended for direct-list-initialization21// well-formed, but dangling reference22A a2(1, f()); // expected-warning {{temporary whose address is used as value}}23// well-formed, but dangling reference24A a4(1.0, 1); // expected-warning {{temporary whose address is used as value}}25A a5(1.0, std::move(n));  // OK26 27 28 29struct B {30  const int& r;31};32B test(int local) {33  return B(1); // expected-warning {{returning address}}34  return B(local); // expected-warning {{address of stack memory}}35}36 37void f(B b);38void test2(int local) {39  // No diagnostic on the following cases where both the aggregate object and40  // temporary end at the end of the full expression.41  f(B(1));42  f(B(local));43}44 45// Test nested struct.46struct C {47  B b;48};49 50struct D {51  C c;52};53 54C c1(B(55  1  // expected-warning {{temporary whose address is used as value}}56)); 57D d1(C(B(58  1  // expected-warning {{temporary whose address is used as value}}59)));60