• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
TEST(CompilerMacros,ModifyDiagnostics)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
51