Skip to content

Commit 504e60a

Browse files
abhinavarorawangkuiyi
authored andcommitted
Fix Cpplint issues in framework/data_type.h and framework/feed_fetch_type.h (#10146)
* Fix CPPLint issues with data_type.h * Fix CPPLint issues with feed_fetch_type.h
1 parent c3162fd commit 504e60a

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

paddle/fluid/framework/data_type.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
#pragma once
16+
#include <string>
1617
#include <typeindex>
1718
#include "paddle/fluid/framework/framework.pb.h"
1819
#include "paddle/fluid/platform/enforce.h"
@@ -22,26 +23,28 @@ namespace paddle {
2223
namespace framework {
2324

2425
inline proto::VarType::Type ToDataType(std::type_index type) {
25-
using namespace paddle::framework::proto;
2626
if (typeid(platform::float16).hash_code() == type.hash_code()) {
2727
return proto::VarType::FP16;
28-
} else if (typeid(float).hash_code() == type.hash_code()) {
28+
} else if (typeid(const float).hash_code() == type.hash_code()) {
29+
// CPPLint complains Using C-style cast. Use static_cast<float>() instead
30+
// One fix to this is to replace float with const float because
31+
// typeid(T) == typeid(const T)
32+
// http://en.cppreference.com/w/cpp/language/typeid
2933
return proto::VarType::FP32;
30-
} else if (typeid(double).hash_code() == type.hash_code()) {
34+
} else if (typeid(const double).hash_code() == type.hash_code()) {
3135
return proto::VarType::FP64;
32-
} else if (typeid(int).hash_code() == type.hash_code()) {
36+
} else if (typeid(const int).hash_code() == type.hash_code()) {
3337
return proto::VarType::INT32;
34-
} else if (typeid(int64_t).hash_code() == type.hash_code()) {
38+
} else if (typeid(const int64_t).hash_code() == type.hash_code()) {
3539
return proto::VarType::INT64;
36-
} else if (typeid(bool).hash_code() == type.hash_code()) {
40+
} else if (typeid(const bool).hash_code() == type.hash_code()) {
3741
return proto::VarType::BOOL;
3842
} else {
3943
PADDLE_THROW("Not supported");
4044
}
4145
}
4246

4347
inline std::type_index ToTypeIndex(proto::VarType::Type type) {
44-
using namespace paddle::framework::proto;
4548
switch (type) {
4649
case proto::VarType::FP16:
4750
return typeid(platform::float16);
@@ -62,7 +65,6 @@ inline std::type_index ToTypeIndex(proto::VarType::Type type) {
6265

6366
template <typename Visitor>
6467
inline void VisitDataType(proto::VarType::Type type, Visitor visitor) {
65-
using namespace paddle::framework::proto;
6668
switch (type) {
6769
case proto::VarType::FP16:
6870
visitor.template operator()<platform::float16>();
@@ -88,7 +90,6 @@ inline void VisitDataType(proto::VarType::Type type, Visitor visitor) {
8890
}
8991

9092
inline std::string DataTypeToString(const proto::VarType::Type type) {
91-
using namespace paddle::framework::proto;
9293
switch (type) {
9394
case proto::VarType::FP16:
9495
return "float16";

paddle/fluid/framework/feed_fetch_type.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
#pragma once
16-
#include <string>
1716
#include <vector>
1817
#include "paddle/fluid/framework/lod_tensor.h"
1918

@@ -22,7 +21,8 @@ namespace framework {
2221
using FeedFetchType = LoDTensor;
2322
using FeedFetchList = std::vector<FeedFetchType>;
2423

25-
static const std::string kFeedOpType = "feed";
26-
static const std::string kFetchOpType = "fetch";
24+
static const char kFeedOpType[] = "feed";
25+
static const char kFetchOpType[] = "fetch";
26+
2727
} // namespace framework
2828
} // namespace paddle

0 commit comments

Comments
 (0)