Skip to content

Commit 4071df9

Browse files
authored
cc: fix returning type of sel_types
Fix the following compiler warning: ``` /home/runner/work/deepmd-kit/deepmd-kit/source/api_c/src/c_api.cc:1336:17: warning: returning address of local temporary object [-Wreturn-stack-address] return (int*)&(dcm->dcm.sel_types())[0]; ^~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. ``` by returning the reference of sel_type. It seems this function is not used anywhere, even in the test, so we don't have an chance to find out if there is possible segfault. (so this warning has no impact) It seems DeepTensor has returned a reference since the beginning (deepmodeling#137). (perhaps because DeepTensor.sel_types is actually used) DeepTensor and DataChargeModifier have different returned types.
1 parent 5c545f7 commit 4071df9

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

source/api_cc/include/DataModifier.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class DipoleChargeModifierBase {
8484
* @brief Get the list of sel types.
8585
* @return The list of sel types.
8686
*/
87-
virtual std::vector<int> sel_types() const = 0;
87+
virtual std::vector<int>& sel_types() const = 0;
8888
};
8989

9090
/**
@@ -161,7 +161,7 @@ class DipoleChargeModifier {
161161
* @brief Get the list of sel types.
162162
* @return The list of sel types.
163163
*/
164-
std::vector<int> sel_types() const;
164+
std::vector<int>& sel_types() const;
165165

166166
private:
167167
bool inited;

source/api_cc/include/DataModifierTF.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class DipoleChargeModifierTF : public DipoleChargeModifierBase {
8484
* @brief Get the list of sel types.
8585
* @return The list of sel types.
8686
*/
87-
std::vector<int> sel_types() const {
87+
std::vector<int>& sel_types() const {
8888
assert(inited);
8989
return sel_type;
9090
};

0 commit comments

Comments
 (0)