{"id":112208,"date":"2026-04-06T07:00:00","date_gmt":"2026-04-06T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=112208"},"modified":"2026-04-06T09:04:42","modified_gmt":"2026-04-06T16:04:42","slug":"20260406-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20260406-00\/?p=112208","title":{"rendered":"Learning to read C++ compiler errors: Illegal use of <TT>-&gt;<\/TT> when there is no <TT>-&gt;<\/TT> in sight"},"content":{"rendered":"<p>A customer reported a problem with a system header file. When they included <tt>ole2.h<\/tt>, the compiler reported an error in <tt>oaidl.h<\/tt>:<\/p>\n<pre>    MIDL_INTERFACE(\"3127CA40-446E-11CE-8135-00AA004BB851\")\r\n    IErrorLog : public IUnknown\r\n    {\r\n    public:\r\n        <span style=\"border: solid 1px currentcolor;\">virtual HRESULT STDMETHODCALLTYPE AddError(<\/span> \/\/ error here\r\n            \/* [in] *\/ __RPC__in LPCOLESTR pszPropName,\r\n            \/* [in] *\/ __RPC__in EXCEPINFO *pExcepInfo) = 0;\r\n        \r\n    };\r\n<\/pre>\n<p>The error message is<\/p>\n<pre style=\"white-space: pre-wrap;\">oaidl.h(5457,43): error C3927: '-&gt;': trailing return type is not allowed after a non-function declarator\r\noaidl.h(5457,43): error C3613: missing return type after '-&gt;' ('int' assumed)\r\noaidl.h(5457,43): error C3646: 'Log': unknown override specifier\r\noaidl.h(5457,43): error C2275: 'LPCOLESTR': expected an expression instead of a type\r\noaidl.h(5457,43): error C2146: syntax error: missing ')' before identifier 'pszPropName'\r\noaidl.h(5459,60): error C2238: unexpected token(s) preceding ';'\r\n<\/pre>\n<p>The compiler is seeing ghosts: It&#8217;s complaining about things that aren&#8217;t there, like <tt>-&gt;<\/tt> and Log.<\/p>\n<p>When you see the compiler reporting errors about things that aren&#8217;t in the code, you should suspect a macro, because macros can insert characters into code.<\/p>\n<p>In this case, I suspected that there is a macro called <code>AddError<\/code> whose expansion includes the token <tt>-&gt;<\/tt>.<\/p>\n<p>The customer reported that they had no such macro.<\/p>\n<p>I asked them to generate a preprocessor file for the code that isn&#8217;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 <tt>-&gt;<\/tt>. Is there really no <tt>-&gt;<\/tt> there?<\/p>\n<p>The customer reported back that, oops, they did indeed have a macro called <code>AddError<\/code>. Disabling the macro fixed the problem.<\/p>\n<p>The compiler can at times be obtuse with its error messages, but as far as I know, it isn&#8217;t malicious. If it complains about a misused <tt>-&gt;<\/tt>, then there is probably a <tt>-&gt;<\/tt> that is being misused.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If the compiler is complaining about things you didn&#8217;t write, find out who wrote them.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-112208","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>If the compiler is complaining about things you didn&#8217;t write, find out who wrote them.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112208","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=112208"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112208\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=112208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=112208"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=112208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}