Intellisense error when using `__FUNCTIONW__`

2019-07-15 10:57发布

问题:

I am using the __LINE__, __FILEW__ and __FUNCTIONW__ macros to aid in the writing and implementation of a custom exception class. As is well known, they automatically provide the line number, source-file name and function name of the location in code from where they are called. Also, as I am working exclusively in Unicode I must use the ...W wide character versions of those that expand to a string result.

For example:

throw CEString(CEString::ERROR_INDEX_OUT_OF_BOUNDS,
                __LINE__,
                L"End index is smaller than start index",
                L"Index Out of Bounds",
                __FILEW__,
                __FUNCTIONW__,
                L"CString");

Where CEString is a custom exception class whose Constructor takes two integer arguments and then five simple wide strings to locate and describe the error for which it is thrown.

I have the header files iostream, new and crtdefs.h properly included. Going from the documentation the latter should not be strictly necessary, but as it is where the macros are actually defined I have included it anyway. However, the Intellisense error-checker in VS2013 highlights my use of the __FUNCTIONW__ macro as an error. It returns the following notification:

Error: identifier L__FUNCTION__ is undefined.

...which is strange!

Where this becomes even stranger is; the programme itself - despite this error warning - compiles happily and what is more even runs as expected. The supposedly debatable macro creates its wide-character function-name expansion without any complaint.

So this is obviously a problem with Intellisense, not the code or headers. Do any of you chaps have an idea what might be going wrong?

This is probably the closest previous question :

Why would __FUNCTION__ be undefined?

However, unlike Ben Voight I find the programme does actually link and run! The problem is explicitly with Intellisense.

回答1:

This bug is already made public to Microsoft.

Intellisense generally seems to have problems with macros even in VS2010 ( self defined or built in )

You should be okay ignoring the error for now.

Also this might give you some insight in what I mean.



回答2:

As a workaround, you can just define the following (preferably in your PCH header)...

#if (_MSC_VER >= 1800 && _MSC_VER <= 1899)
#define L__FUNCTION__ nullptr
#define L__FILE__     nullptr
#endif

It's a useless definition, but it stops IntelliSense from reporting the "undefined" expansion.