| 1 |
/* PR c++/85021: Verify that we suggest missing headers for common names in std:: |
| 2 |
if there's a "using namespace std;" active. */ |
| 3 |
|
| 4 |
/* No using-directive. */ |
| 5 |
|
| 6 |
void test_1 () |
| 7 |
{ |
| 8 |
cout << "test"; // { dg-error "'cout' was not declared in this scope" } |
| 9 |
// { dg-bogus "'<iostream>'" "" { target *-*-* } .-1 } |
| 10 |
} |
| 11 |
|
| 12 |
/* Local using-directive. */ |
| 13 |
|
| 14 |
void test_2 () |
| 15 |
{ |
| 16 |
using namespace std; |
| 17 |
cout << "test"; // { dg-error "'cout' was not declared in this scope" } |
| 18 |
// { dg-message "'std::cout' is defined in header '<iostream>'" "" { target *-*-* } .-1 } |
| 19 |
} |
| 20 |
|
| 21 |
/* Local using-directive, but not of "std". */ |
| 22 |
|
| 23 |
namespace not_std {} |
| 24 |
void test_3 () |
| 25 |
{ |
| 26 |
using namespace not_std; |
| 27 |
cout << "test"; // { dg-error "'cout' was not declared in this scope" } |
| 28 |
// { dg-bogus "'<iostream>'" "" { target *-*-* } .-1 } |
| 29 |
} |
| 30 |
|
| 31 |
/* Local using-directive in wrong block. */ |
| 32 |
|
| 33 |
void test_4 () |
| 34 |
{ |
| 35 |
{ |
| 36 |
using namespace std; |
| 37 |
} |
| 38 |
cout << "test"; // { dg-error "'cout' was not declared in this scope" } |
| 39 |
// { dg-bogus "'<iostream>'" "" { target *-*-* } .-1 } |
| 40 |
} |
| 41 |
|
| 42 |
/* Local using-directive used from nested block. */ |
| 43 |
|
| 44 |
void test_5 () |
| 45 |
{ |
| 46 |
using namespace std; |
| 47 |
|
| 48 |
for (int i = 0; i < 10; i++) |
| 49 |
{ |
| 50 |
cout << "test"; // { dg-error "'cout' was not declared in this scope" } |
| 51 |
// { dg-message "'std::cout' is defined in header '<iostream>'" "" { target *-*-* } .-1 } |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
namespace ns_1 { |
| 56 |
|
| 57 |
namespace ns_2 { |
| 58 |
|
| 59 |
using namespace std; |
| 60 |
|
| 61 |
/* using-directive within the same namespace. */ |
| 62 |
|
| 63 |
void test_6 () |
| 64 |
{ |
| 65 |
cout << "test"; // { dg-error "'cout' was not declared in this scope" } |
| 66 |
// { dg-message "'std::cout' is defined in header '<iostream>'" "" { target *-*-* } .-1 } |
| 67 |
} |
| 68 |
|
| 69 |
namespace ns_3 { |
| 70 |
|
| 71 |
/* Locate the using-directive within ns_2, the parent namespace. */ |
| 72 |
|
| 73 |
void test_7 () |
| 74 |
{ |
| 75 |
cout << "test"; // { dg-error "'cout' was not declared in this scope" } |
| 76 |
// { dg-message "'std::cout' is defined in header '<iostream>'" "" { target *-*-* } .-1 } |
| 77 |
} |
| 78 |
|
| 79 |
} // namespace ns_3 |
| 80 |
} // namespace ns_2 |
| 81 |
|
| 82 |
/* Back in ns_1, should not locate the using-directive. */ |
| 83 |
|
| 84 |
void test_8 () |
| 85 |
{ |
| 86 |
cout << "test"; // { dg-error "'cout' was not declared in this scope" } |
| 87 |
// { dg-bogus "'<iostream>'" "" { target *-*-* } .-1 } |
| 88 |
} |
| 89 |
|
| 90 |
} // namespace ns_1 |
| 91 |
|
| 92 |
/* using-directive in global namespace. */ |
| 93 |
using namespace std; |
| 94 |
|
| 95 |
void test_9 () |
| 96 |
{ |
| 97 |
cout << "test"; // { dg-error "'cout' was not declared in this scope" } |
| 98 |
// { dg-message "'std::cout' is defined in header '<iostream>'" "" { target *-*-* } .-1 } |
| 99 |
} |
| 100 |
|