Manuel Klimek | b91bee0 | 2015-10-22 11:31:44 +0000 | [diff] [blame] | 1 | // RUN: %check_clang_tidy %s google-runtime-member-string-references %t |
Benjamin Kramer | b103975 | 2014-07-16 10:00:14 +0000 | [diff] [blame] | 2 | |
| 3 | namespace std { |
| 4 | template<typename T> |
| 5 | class basic_string {}; |
| 6 | |
| 7 | typedef basic_string<char> string; |
| 8 | } |
| 9 | |
| 10 | class string {}; |
| 11 | |
| 12 | |
| 13 | struct A { |
| 14 | const std::string &s; |
Alexander Kornienko | 106c8e0 | 2014-10-26 02:58:07 +0000 | [diff] [blame] | 15 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: const string& members are dangerous. It is much better to use alternatives, such as pointers or simple constants. [google-runtime-member-string-references] |
Benjamin Kramer | b103975 | 2014-07-16 10:00:14 +0000 | [diff] [blame] | 16 | }; |
| 17 | |
| 18 | struct B { |
| 19 | std::string &s; |
| 20 | }; |
| 21 | |
| 22 | struct C { |
| 23 | const std::string s; |
| 24 | }; |
| 25 | |
| 26 | template <typename T> |
| 27 | struct D { |
| 28 | D(); |
| 29 | const T &s; |
| 30 | const std::string &s2; |
Alexander Kornienko | 106c8e0 | 2014-10-26 02:58:07 +0000 | [diff] [blame] | 31 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: const string& members are dangerous. |
Benjamin Kramer | b103975 | 2014-07-16 10:00:14 +0000 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | D<std::string> d; |
| 35 | |
| 36 | struct AA { |
| 37 | const string &s; |
Alexander Kornienko | 106c8e0 | 2014-10-26 02:58:07 +0000 | [diff] [blame] | 38 | // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: const string& members are dangerous. |
Benjamin Kramer | b103975 | 2014-07-16 10:00:14 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | struct BB { |
| 42 | string &s; |
| 43 | }; |
| 44 | |
| 45 | struct CC { |
| 46 | const string s; |
| 47 | }; |
| 48 | |
| 49 | D<string> dd; |