blob: b153149ca39c3be69d913991c4ee7dbe5df803ac [file] [log] [blame]
Manuel Klimekb91bee02015-10-22 11:31:44 +00001// RUN: %check_clang_tidy %s google-runtime-member-string-references %t
Benjamin Kramerb1039752014-07-16 10:00:14 +00002
3namespace std {
4template<typename T>
5 class basic_string {};
6
7typedef basic_string<char> string;
8}
9
10class string {};
11
12
13struct A {
14 const std::string &s;
Alexander Kornienko106c8e02014-10-26 02:58:07 +000015// 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 Kramerb1039752014-07-16 10:00:14 +000016};
17
18struct B {
19 std::string &s;
20};
21
22struct C {
23 const std::string s;
24};
25
26template <typename T>
27struct D {
28 D();
29 const T &s;
30 const std::string &s2;
Alexander Kornienko106c8e02014-10-26 02:58:07 +000031// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: const string& members are dangerous.
Benjamin Kramerb1039752014-07-16 10:00:14 +000032};
33
34D<std::string> d;
35
36struct AA {
37 const string &s;
Alexander Kornienko106c8e02014-10-26 02:58:07 +000038// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: const string& members are dangerous.
Benjamin Kramerb1039752014-07-16 10:00:14 +000039};
40
41struct BB {
42 string &s;
43};
44
45struct CC {
46 const string s;
47};
48
49D<string> dd;