我有以下情况:
CRITICAL_SECTION CriticalSection;
class NF3DLock
{
public:
#pragma prefast( suppress:26166, "Thread safeness is enabeled." )
FORCEINLINE _Acquires_lock_(CriticalSection) NF3DLock(void) { EnterCriticalSection(&CriticalSection); }
#pragma prefast( suppress:26165, "Thread safeness is enabeled." )
FORCEINLINE _Releases_lock_(CriticalSection) ~NF3DLock(void) { LeaveCriticalSection(&CriticalSection); }
};
此代码段编译完美,我在Visual Studio 2013 Ultimate下没有得到代码分析的警告。但如果我把它改为:
CRITICAL_SECTION* GetCriticalSection(void)
{
static CRITICAL_SECTION CriticalSection;
return &CriticalSection;
}
class NF3DLock
{
public:
#pragma prefast( suppress:26166, "Thread safeness is enabeled." )
FORCEINLINE _Acquires_lock_(GetCriticalSection()) NF3DLock(void) { EnterCriticalSection(GetCriticalSection()); }
#pragma prefast( suppress:26165, "Thread safeness is enabeled." )
FORCEINLINE _Releases_lock_(GetCriticalSection()) ~NF3DLock(void) { LeaveCriticalSection(GetCriticalSection()); }
};
代码分析说:
e:\new frontiers\newfrontiers3d\header files\state.h(52): warning C28285: For function '{ctor}' 'return' syntax error in 'SAL_acquires_lock(NF3DGetCriticalSection())' near '())'.
e:\new frontiers\newfrontiers3d\header files\state.h(54): warning C28285: For function '{dtor}' 'return' syntax error in 'SAL_releases_lock(NF3DGetCriticalSection())' near '())'.
有人知道解决这个问题的方法吗?谢谢你的帮助。