Wyatt Hepler | 38b6d44 | 2021-04-09 15:32:34 -0700 | [diff] [blame] | 1 | // Copyright 2021 The Pigweed Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 4 | // use this file except in compliance with the License. You may obtain a copy of |
| 5 | // the License at |
| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | // License for the specific language governing permissions and limitations under |
| 13 | // the License. |
| 14 | |
| 15 | #include "pw_preprocessor/compiler.h" |
| 16 | |
| 17 | #include <cstdint> |
| 18 | |
| 19 | #include "gtest/gtest.h" |
| 20 | |
| 21 | namespace pw::preprocessor { |
| 22 | namespace { |
| 23 | |
| 24 | PW_MODIFY_DIAGNOSTICS_PUSH(); |
| 25 | PW_MODIFY_DIAGNOSTIC(ignored, "-Wunused-variable"); |
| 26 | |
| 27 | int this_variable_is_unused; |
| 28 | |
| 29 | PW_MODIFY_DIAGNOSTICS_POP(); |
| 30 | |
| 31 | class Foo { |
| 32 | PW_MODIFY_DIAGNOSTICS_PUSH(); |
| 33 | PW_MODIFY_DIAGNOSTIC(ignored, "-Wunused"); |
| 34 | |
| 35 | int this_field_is_unused; |
| 36 | |
| 37 | PW_MODIFY_DIAGNOSTICS_POP(); |
| 38 | }; |
| 39 | |
| 40 | TEST(CompilerMacros, ModifyDiagnostics) { |
| 41 | PW_MODIFY_DIAGNOSTICS_PUSH(); |
| 42 | PW_MODIFY_DIAGNOSTIC(ignored, "-Wunused-variable"); |
| 43 | |
| 44 | int this_variable_also_is_unused; |
| 45 | |
| 46 | PW_MODIFY_DIAGNOSTICS_POP(); |
| 47 | } |
| 48 | |
| 49 | } // namespace |
| 50 | } // namespace pw::preprocessor |