A customer reported a problem with a system header file. When they included ole2.h, the compiler reported an error in oaidl.h:
MIDL_INTERFACE("3127CA40-446E-11CE-8135-00AA004BB851")
IErrorLog : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE AddError( // error here
/* [in] */ __RPC__in LPCOLESTR pszPropName,
/* [in] */ __RPC__in EXCEPINFO *pExcepInfo) = 0;
};
The error message is
oaidl.h(5457,43): error C3927: '->': trailing return type is not allowed after a non-function declarator
oaidl.h(5457,43): error C3613: missing return type after '->' ('int' assumed)
oaidl.h(5457,43): error C3646: 'Log': unknown override specifier
oaidl.h(5457,43): error C2275: 'LPCOLESTR': expected an expression instead of a type
oaidl.h(5457,43): error C2146: syntax error: missing ')' before identifier 'pszPropName'
oaidl.h(5459,60): error C2238: unexpected token(s) preceding ';'
The compiler is seeing ghosts: It’s complaining about things that aren’t there, like -> and Log.
When you see the compiler reporting errors about things that aren’t in the code, you should suspect a macro, because macros can insert characters into code.
In this case, I suspected that there is a macro called AddError whose expansion includes the token ->.
The customer reported that they had no such macro.
I asked them to generate a preprocessor file for the code that isn’t compiling. That way, we can see what is being produced by the preprocessor before it goes into the part of the compiler that is complaining about the illegal use of ->. Is there really no -> there?
The customer reported back that, oops, they did indeed have a macro called AddError. Disabling the macro fixed the problem.
The compiler can at times be obtuse with its error messages, but as far as I know, it isn’t malicious. If it complains about a misused ->, then there is probably a -> that is being misused.
The post Learning to read C++ compiler errors: Illegal use of <TT>-></TT> when there is no <TT>-></TT> in sight appeared first on The Old New Thing.
