40 lines · cpp
1// RUN: %clang_cc1 -verify -std=c++11 -Wdangling-assignment-gsl %s2 3using T = int[];4 5void f() {6 int *p = &(int&)(int&&)0; // expected-warning {{temporary whose address is used as value of local variable 'p' will be destroyed at the end of the full-expression}}7 p = &(int&)(int&&)0; // expected-warning {{object backing the pointer 'p' will be destroyed at the end of the full-expression}}8 9 int *q = (int *const &)T{1, 2, 3}; // expected-warning {{temporary whose address is used as value of local variable 'q' will be destroyed at the end of the full-expression}}10 q = (int *const &)T{1, 2, 3}; // expected-warning {{object backing the pointer 'q' will be destroyed at the end of the full-expression}}11 12 // FIXME: We don't warn here because the 'int*' temporary is not const, but13 // it also can't have actually changed since it was created, so we could14 // still warn.15 int *r = (int *&&)T{1, 2, 3};16 17 // FIXME: The wording of this warning is not quite right. There are two18 // temporaries here: an 'int* const' temporary that points to the array, and19 // is lifetime-extended, and an array temporary that the pointer temporary20 // points to, which doesn't live long enough.21 int *const &s = (int *const &)T{1, 2, 3}; // expected-warning {{temporary bound to local reference 's' will be destroyed at the end of the full-expression}}22}23 24// PR3835525void g() {26 const int a[] = {a[0]};27 const int b[] = {a[0]};28}29 30namespace std {31// std::basic_string has a hard-coded gsl::owner attr.32struct basic_string {33 const char* c_str();34};35} // namespace std36void test(const char* a) {37 // verify we're emitting the `-Wdangling-assignment-gsl` warning.38 a = std::basic_string().c_str(); // expected-warning {{object backing the pointer 'a' will be destroyed at the end of the full-expression}}39}40