Introduce Q_DECL_CONST_FUNCTION and Q_DECL_PURE_FUNCTION

That expand to __attribute__((const)) and ((pure)). A "const" function
is a function allowed to examine only its arguments, without modifying
them. A "pure" function is also allowed to read memory.

Currently working only on GCC/ICC/Clang, MSVC lacks these.

Change-Id: Ie60a0847b193fb88e116f61611dc571296a3df1c
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Giuseppe D'Angelo 2014-03-01 14:12:33 +01:00 committed by The Qt Project
parent b72880d213
commit d85983ece7
2 changed files with 10 additions and 0 deletions

View File

@ -27,9 +27,11 @@ Cpp.ignoretokens += \
Q_CORE_EXPORT_INLINE \
Q_DBUS_EXPORT \
Q_DECL_CONSTEXPR \
Q_DECL_CONST_FUNCTION \
Q_DECL_DEPRECATED \
Q_DECL_NOEXCEPT \
Q_DECL_NOTHROW \
Q_DECL_PURE_FUNCTION \
Q_DECL_UNUSED \
Q_DECLARATIVE_EXPORT \
Q_EXPLICIT \

View File

@ -200,6 +200,8 @@
# define Q_UNLIKELY(expr) __builtin_expect(!!(expr), false)
# define Q_NORETURN __attribute__((__noreturn__))
# define Q_REQUIRED_RESULT __attribute__ ((__warn_unused_result__))
# define Q_DECL_PURE_FUNCTION __attribute__((pure))
# define Q_DECL_CONST_FUNCTION __attribute__((const))
# if !defined(QT_MOC_CPP)
# define Q_PACKED __attribute__ ((__packed__))
# ifndef __ARM_EABI__
@ -975,6 +977,12 @@
#ifndef Q_DECL_NS_RETURNS_AUTORELEASED
# define Q_DECL_NS_RETURNS_AUTORELEASED
#endif
#ifndef Q_DECL_PURE_FUNCTION
# define Q_DECL_PURE_FUNCTION
#endif
#ifndef Q_DECL_CONST_FUNCTION
# define Q_DECL_CONST_FUNCTION Q_DECL_PURE_FUNCTION
#endif
/*
Workaround for static const members on MSVC++.