|
1 | 1 | // RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -Wno-c++1y-extensions -verify %s
|
2 |
| -// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -Wno-c++1y-extensions -verify -std=gnu++11 %s |
| 2 | +// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -Wno-c++1y-extensions -verify=expected,cxx98-14 -std=gnu++11 %s |
| 3 | +// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -Wno-c++1y-extensions -verify=expected,cxx98-14 -std=gnu++14 %s |
| 4 | +// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -Wno-c++1y-extensions -verify -std=gnu++17 %s |
3 | 5 | template<typename T> void f() {
|
4 | 6 | T t;
|
5 | 7 | t = 17;
|
@@ -183,7 +185,8 @@ void foo(int size) {
|
183 | 185 | NonTriviallyDestructible array[2]; // no warning
|
184 | 186 | NonTriviallyDestructible nestedArray[2][2]; // no warning
|
185 | 187 |
|
186 |
| - Foo fooScalar = 1; // expected-warning {{unused variable 'fooScalar'}} |
| 188 | + // Copy initialzation gives warning before C++17 |
| 189 | + Foo fooScalar = 1; // cxx98-14-warning {{unused variable 'fooScalar'}} |
187 | 190 | Foo fooArray[] = {1,2}; // expected-warning {{unused variable 'fooArray'}}
|
188 | 191 | Foo fooNested[2][2] = { {1,2}, {3,4} }; // expected-warning {{unused variable 'fooNested'}}
|
189 | 192 | }
|
@@ -297,3 +300,29 @@ void RAIIWrapperTest() {
|
297 | 300 | }
|
298 | 301 |
|
299 | 302 | } // namespace gh54489
|
| 303 | + |
| 304 | +// Ensure that -Wunused-variable does not emit warning |
| 305 | +// on copy constructors with side effects (C++17 and later) |
| 306 | +#if __cplusplus >= 201703L |
| 307 | +namespace gh79518 { |
| 308 | + |
| 309 | +struct S { |
| 310 | + S(int); |
| 311 | +}; |
| 312 | + |
| 313 | +// With an initializer list |
| 314 | +struct A { |
| 315 | + int x; |
| 316 | + A(int x) : x(x) {} |
| 317 | +}; |
| 318 | + |
| 319 | +void foo() { |
| 320 | + S s(0); // no warning |
| 321 | + S s2 = 0; // no warning |
| 322 | + S s3{0}; // no warning |
| 323 | + |
| 324 | + A a = 1; // no warning |
| 325 | +} |
| 326 | + |
| 327 | +} // namespace gh79518 |
| 328 | +#endif |
0 commit comments