Roy T.
Roy T.

Reputation: 9638

#pragma warning disable ignored inside array initializer

I was trying to create a small define to work around this bug in QITABENT and I noticed peculiar behavior of the #pragma warning (disable: ...) statement.

In the following code the define QITABENT generates warning C4838

static const QITAB qit[] = 
{
    QITABENT(MediaPlayerCallback, IMFPMediaPlayerCallback)
};

I can easily suppress this warning, this works:

#pragma warning( push )
#pragma warning( disable: 4838 )

    static const QITAB qit[] = 
    {
        QITABENT(MediaPlayerCallback, IMFPMediaPlayerCallback)
        //{ 0 },
    };
    return QISearch(this, qit, riid, ppv);

#pragma warning( pop )

Now I wanted to make a define QITABENTEX which automatically suppresses the warning generated by QITABENT. But it seems impossible because when I write the following code the warning C4838 is not suppressed.

    static const QITAB qit[] = 
    {
#pragma warning( push )
#pragma warning( disable: 4838 )
        QITABENT(MediaPlayerCallback, IMFPMediaPlayerCallback)
#pragma warning( pop )
        //{ 0 },
    };

How does the compiler interpret this code in such a way that the warning is not suppressed?

This probably has to with when the definition for QITABENT is fully resolved.

(Note that I'm not really interested in making the above code work, I'm just really curious how its interpreted by the compiler)

Addendum:

Regarding the close vote and clarification: I got into a discussion with someone giving a shotgun/link-only answer, presumably only reading the question halfway through (since the question explained how to use #pragma in a macro which is not what I'm asking) now that answer got (self) deleted and I got a close vote for being unclear. So let me reiterate my intentions with this question:

Upvotes: 3

Views: 1236

Answers (1)

Vlad Feinstein
Vlad Feinstein

Reputation: 11311

The initializer list terminates with the closing curly bracket }, and that is where warning is generated.

Try this:

static const QITAB qit[] =
{
    QITABENT(Derived, Base)
#pragma warning( push )
#pragma warning( disable: 4365 )
}
#pragma warning( pop )
;

[edited] Per Mr.C64's comment below, corrected the order of parameters in QITABENT(Derived, Base).

Upvotes: 6

Related Questions