Skip to content

Commit

Permalink
cc: fix returning type of sel_types
Browse files Browse the repository at this point in the history
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 (#137). (perhaps because DeepTensor.sel_types is actually used) DeepTensor and DataChargeModifier have different returned types.
  • Loading branch information
njzjz authored Jan 26, 2024
1 parent 5c545f7 commit 4071df9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions source/api_cc/include/DataModifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class DipoleChargeModifierBase {
* @brief Get the list of sel types.
* @return The list of sel types.
*/
virtual std::vector<int> sel_types() const = 0;
virtual std::vector<int>& sel_types() const = 0;
};

/**
Expand Down Expand Up @@ -161,7 +161,7 @@ class DipoleChargeModifier {
* @brief Get the list of sel types.
* @return The list of sel types.
*/
std::vector<int> sel_types() const;
std::vector<int>& sel_types() const;

private:
bool inited;
Expand Down
2 changes: 1 addition & 1 deletion source/api_cc/include/DataModifierTF.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class DipoleChargeModifierTF : public DipoleChargeModifierBase {
* @brief Get the list of sel types.
* @return The list of sel types.
*/
std::vector<int> sel_types() const {
std::vector<int>& sel_types() const {
assert(inited);
return sel_type;
};
Expand Down

0 comments on commit 4071df9

Please sign in to comment.