![](/img/trans.png)
[英]Using Microsoft's Source-Code Annotation Language (SAL) with Doxygen?
[英]Microsoft source code annotation language (SAL) does not give C26100 or other warnings
我想看看是否可以使用 SAL 來檢測並發錯誤。 我根據Sample C++ 項目准備了一個項目進行代碼分析,並嘗試了Code analysis for C/C++ warnings中的示例代碼。
但是,我沒有收到應出現在某些示例代碼中的警告。 具體來說,C26100、C26101、C26110、C26111、C26112、C26115、C2611 和 C26140 會收到警告,但 C26105、C26116、C26130、C26135、C26160、C26165、C26166 和 C26167 不會。
對於 C26105,我們在C26105上嘗試了以下代碼
#include <sal.h>
#include <Windows.h>
_Create_lock_level_(MutexLockLevel);
_Create_lock_level_(TunnelLockLevel);
_Create_lock_level_(ChannelLockLevel);
_Lock_level_order_(MutexLockLevel, TunnelLockLevel);
_Lock_level_order_(TunnelLockLevel, ChannelLockLevel);
_Has_lock_level_(MutexLockLevel) HANDLE gMutex;
struct Tunnel
{
_Has_lock_level_(TunnelLockLevel) CRITICAL_SECTION cs;
};
struct Channel
{
_Has_lock_level_(ChannelLockLevel) CRITICAL_SECTION cs;
};
void OrderInversion(Channel* pChannel, Tunnel* pTunnel)
{
EnterCriticalSection(&pChannel->cs);
// I expect Warning C26105, but no warning.
WaitForSingleObject(gMutex, INFINITE);
EnterCriticalSection(&pTunnel->cs);
LeaveCriticalSection(&pTunnel->cs);
LeaveCriticalSection(&pChannel->cs);
}
為什么是這樣? 如果您有任何信息,如果您能告訴我,我將不勝感激。
我的環境如下。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.