提交 109fc93b 编写于 作者: Y Yu Yang 提交者: GitHub

Merge pull request #2600 from reyoung/feature/moving_compiler_flags_to_platform

Adding platform/must_check.h
...@@ -2,3 +2,4 @@ nv_test(cuda_test SRCS cuda_test.cu) ...@@ -2,3 +2,4 @@ nv_test(cuda_test SRCS cuda_test.cu)
cc_library(place SRCS place.cc) cc_library(place SRCS place.cc)
cc_test(place_test SRCS place_test.cc DEPS place glog gflags) cc_test(place_test SRCS place_test.cc DEPS place glog gflags)
cc_test(must_check_test SRCS must_check_test.cc)
...@@ -10,24 +10,17 @@ See the License for the specific language governing permissions and ...@@ -10,24 +10,17 @@ See the License for the specific language governing permissions and
limitations under the License. */ limitations under the License. */
#pragma once #pragma once
/**
* This header defines some useful attribute by each compiler. It is the
* abstract layer of compilers.
*/
#ifdef __GNUC__
#define GCC_VERSION \
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#else
#define GCC_VERSION
#endif
/** /**
* __must_check macro. It make the function's return value must be used, * __must_check macro. It make the function's return value must be used,
* otherwise it will raise a compile warning. And also Paddle treat all compile * otherwise it will raise a compile warning. And also Paddle treat all compile
* warnings as errors. * warnings as errors.
*/ */
#if GCC_VERSION >= 30400 #ifdef __GNUC__
#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 30400
#define __must_check __attribute__((warn_unused_result)) #define __must_check __attribute__((warn_unused_result))
#else #else
#define __must_check #define __must_check
#endif #endif
#else
#define __must_check
#endif
#include <gtest/gtest.h>
#include <paddle/platform/must_check.h>
int __must_check SomeFunctionMustCheck() { return 0; }
TEST(MustCheck, all) {
// This line should not be compiled, because the
// return value of SomeFunctionMustCheck marked as __must_check
// SomeFunctionMustCheck();
}
\ No newline at end of file
...@@ -19,7 +19,7 @@ limitations under the License. */ ...@@ -19,7 +19,7 @@ limitations under the License. */
#include <stdio.h> #include <stdio.h>
#include <memory> #include <memory>
#include <string> #include <string>
#include "Compiler.h" #include "paddle/platform/must_check.h"
namespace paddle { namespace paddle {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册