system_header pragma

ファイルの残りの部分を診断レポートの外部として扱います。

構文

#pragma system_header

解説

system_headerpragma は、現在のソースファイルの残りの部分について、/external:Wn オプションで指定されたレベルで診断を表示するようコンパイラに指示します。 外部ファイルと外部警告レベルをコンパイラに指定する方法の詳細については、「/external」を参照してください。

system_headerpragma は、現在のソース ファイルの末尾を越えては適用されません。 つまり、このファイルを含むファイルには適用されません。 system_headerpragma は、コンパイラの外部として指定される他のファイルがない場合でも適用されます。 ただし、/external:Wn オプション レベルが指定されていない場合、コンパイラは診断を発行して非外部ファイルに適用されるのと同じ警告レベルを使用する場合があります。 警告動作に影響を与える他の pragma ディレクティブは、system_headerpragma の後でも適用されます。 #pragma system_header の効果は warning pragma のようになります。

// If n represents the warning level specified by /external:Wn,
// #pragma system_header is roughly equivalent to:
#pragma warning( push, n )

// . . .

// At the end of the file:
#pragma warning( pop )

system_headerpragma は、Visual Studio 2019 バージョン 16.10 以降で使用できます。

このサンプル ヘッダーは、ファイルの内容を外部としてマークする方法を示しています。

// library.h
// Use /external:Wn to set the compiler diagnostics level for this file's contents

#pragma once
#ifndef _LIBRARY_H // include guard for 3rd party interop
#define _LIBRARY_H
#pragma system_header
// The compiler applies the /external:Wn diagnostic level from here to the end of this file.

// . . .

// You can still override the external diagnostic level for warnings locally:
#pragma warning( push )
#pragma warning( error : 4164 )

// . . .

#pragma warning(pop)

// . . .

#endif

関連項目

/external
warning pragma
/Wn (コンパイラの警告レベル)
pragma ディレクティブと __pragma および _Pragma キーワード