问题描述
我有一个特定的警告,我想删除/隐藏然后立即启用它。你知道如何在不删除所有其他警告的情况下做到这一点吗?
这是我收到的警告
warning: enumeration value 'EtatCCSortie' not handled in switch [-Wswitch]
而且我不需要在开关中实际使用该状态(它是一个状态机)。我有一种方法可以不再收到此警告,方法是将状态添加到开关中,如下所示:
while (etatsImprimanteCasImpressionPeriodique != EtatIPSortie)
{
switch (etatsImprimanteCasChangementCartouche)
{
....
case EtatCCSortie:
break;
但我不必添加它,因为它永远不会执行(虽然!=)。这就是为什么我正在寻找一种方法来禁用此特定警告,然后在此切换后立即启用它。
解决方法
enum somenum {
EtatIPSortie,EtatCCSortie,};
int etatsImprimanteCasImpressionPeriodique;
enum somenum etatsImprimanteCasChangementCartouche;
void func() {
while (etatsImprimanteCasImpressionPeriodique != EtatIPSortie)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch"
switch (etatsImprimanteCasChangementCartouche)
{
case EtatCCSortie:
break;
}
#pragma GCC diagnostic pop
}
}
,
使用:
#pragma GCC diagnostic ignored "-W<replace_this_with_the_warning>"