Skip to content

Commit 07d8a2e

Browse files
zxy.monadoclaude
andcommitted
Fix: close the access-control regions that ran to end of file
Sixteen test files opened `#define private public` (usually `#define protected public` too) and never closed it, so from the include block onwards the whole translation unit compiled with `private` and `protected` meaning `public` -- up to 1016 lines in `charge_mixing_test.cpp`. `elecstate_pw_test.cpp` was a partial case: it closed `protected` 318 lines later at the end of the file, and never closed `private` at all. Each `#undef` now sits immediately after the include block it is meant to cover. No include is moved: in every one of these files the standard headers already came after the project headers, so they simply fall outside the region once it is closed. That removes the incidental treatment of `<omp.h>` (charge_mixing_test), `<string>` (elecstate_energy_test), `<fstream>` (verlet_test), `<mpi.h>` and `<source_base/module_external/scalapack_connector.h>` (propagator_test1/2/3), `<source_base/macros.h>` (test_hsolver) and `"mpi.h"` (read_wf2rho_pw_test). Closing a region early is safe: the class definitions the tests reach into have already been compiled by the time the `#undef` is seen. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent a8e5e9a commit 07d8a2e

16 files changed

Lines changed: 27 additions & 1 deletion

File tree

source/source_esolver/test/esolver_dp_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define protected public
77
#include "../esolver_dp.h"
88
#include "source_io/module_parameter/input_parameter.h"
9+
#undef protected
910
#undef private
1011
/************************************************
1112
* unit tests of class ESolver_DP

source/source_estate/test/charge_mixing_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "source_basis/module_pw/pw_basis.h"
77
#include "source_hamilt/module_xc/xc_functional.h"
88
#include "source_io/module_parameter/parameter.h"
9+
#undef private
910

1011
#ifdef _OPENMP
1112
#include <omp.h>

source/source_estate/test/charge_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "source_hamilt/module_xc/xc_functional.h"
99
#include "source_io/module_parameter/parameter.h"
1010
#include "prepare_unitcell.h"
11+
#undef protected
12+
#undef private
1113
// mock functions for UnitCell
1214

1315
Magnetism::Magnetism()

source/source_estate/test/elecstate_energy_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "source_estate/elecstate.h"
55
#include "source_hamilt/module_xc/xc_functional.h"
66
#include "source_io/module_parameter/parameter.h"
7+
#undef private
78

89
#include <string>
910
Parameter PARMA;

source/source_estate/test/elecstate_pw_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "source_pw/module_pwdft/vnl_pw.h"
1111
#include "source_pw/module_pwdft/soc.h"
1212
#include "source_io/module_parameter/parameter.h"
13+
#undef protected
14+
#undef private
1315
// mock functions for testing
1416
int XC_Functional::func_type = 1;
1517
namespace elecstate
@@ -323,4 +325,3 @@ TEST_F(ElecStatePWTest, ParallelKSingle)
323325
EXPECT_NO_THROW(elecstate_pw_s->parallelK());
324326
}
325327

326-
#undef protected

source/source_hsolver/test/test_hsolver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "hsolver_supplementary_mock.h"
77
#include "source_hamilt/hamilt.h"
88
#include "source_hsolver/hsolver.h"
9+
#undef protected
910

1011
#include <source_base/macros.h>
1112

source/source_io/test/read_wf2rho_pw_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "source_io/module_wf/read_wf2rho_pw.h"
1616
#include "source_io/module_wf/write_wfc_pw.h"
1717
#include "source_psi/psi.h"
18+
#undef private
1819

1920
#ifdef __MPI
2021
#include "mpi.h"

source/source_lcao/module_rt/test/propagator_test1.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "source_lcao/module_rt/propagator.h"
66
#include "source_io/module_parameter/parameter.h"
77
#include "tddft_test.h"
8+
#undef protected
9+
#undef private
810

911
#include <source_base/module_external/scalapack_connector.h>
1012
#include <mpi.h>

source/source_lcao/module_rt/test/propagator_test2.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "source_lcao/module_rt/propagator.h"
66
#include "source_io/module_parameter/parameter.h"
77
#include "tddft_test.h"
8+
#undef protected
9+
#undef private
810

911
#include <source_base/module_external/scalapack_connector.h>
1012
#include <mpi.h>

source/source_lcao/module_rt/test/propagator_test3.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "source_lcao/module_rt/propagator.h"
66
#include "source_io/module_parameter/parameter.h"
77
#include "tddft_test.h"
8+
#undef protected
9+
#undef private
810

911
#include <source_base/module_external/scalapack_connector.h>
1012
#include <mpi.h>

0 commit comments

Comments
 (0)