This is an archive of the discontinued LLVM Phabricator instance.

Fix error in Visual Studio due to __has_cpp_attribute
AbandonedPublic

Authored by haozhun on Jan 24 2019, 3:24 PM.

Details

Summary

Visual Studio introduced __has_cpp_attributed in 15.8. However, Visual
Studio IntelliSense does not allow :: in __has_cpp_attributed, and
produces error "E2512 the argument to a feature-test macro must be a
simple identifier" for code like #if __has_cpp_attribute(clang::...).

The VS compiler does not produce this error. The error is only produced
by VS IntelliSense. As a result, without this commit, although the code
produces an error in Visual Studio development environment, it does not
make the actual build fail.

Diff Detail

Event Timeline

haozhun created this revision.Jan 24 2019, 3:24 PM
haozhun updated this revision to Diff 183418.Jan 24 2019, 3:34 PM

I'm new to LLVM. I found the reviewer using blame and CODE_OWNERS.TXT. Please let me know if you are not the appropriate reviewer, @chandlerc.

aaron.ballman added a subscriber: aaron.ballman.

Visual Studio introduced has_cpp_attributed in 15.8. However, Visual
Studio IntelliSense does not allow :: in
has_cpp_attributed, and
produces error "E2512 the argument to a feature-test macro must be a
simple identifier" for code like #if __has_cpp_attribute(clang::...).

This is a Visual Studio bug with their IntelliSense implementation. http://eel.is/c++draft/cpp.cond#5 says the pp-tokens are to be interpreted as an attribute-token, which includes attribute-scoped-tokens.

The VS compiler does not produce this error. The error is only produced
by VS IntelliSense. As a result, without this commit, although the code
produces an error in Visual Studio development environment, it does not
make the actual build fail.

IntelliSense squiggly lines often do not match the compiler behavior (IntelliSense uses a different frontend than cl, from what I understand); why do we need to work around it here? I guess I don't understand what problem this is solving given that the compilation succeeds.

Thank you for your review.

This is a Visual Studio bug with their IntelliSense implementation. http://eel.is/c++draft/cpp.cond#5 says the pp-tokens are to be interpreted as an attribute-token, which includes attribute-scoped-tokens.

Thank you for pointing this out and providing citations. I understand that Windows is a supported platform of LLVM. As a result, I suppose it doesn't matter whose fault this is.

IntelliSense squiggly lines often do not match the compiler behavior (IntelliSense uses a different frontend than cl, from what I understand); why do we need to work around it here? I guess I don't understand what problem this is solving given that the compilation succeeds.

If there isn't already a policy/consensus on whether IntelliSense errors should be avoided (especially in header files), it would be a judgement call.

However, I would expect that the choice had been made in the past. If IntelliSense misbehavior are indeed "often" (as you said), and given that there aren't other IntelliSense complaints of header files in the code base (as far as I can tell), it is likely that a choice had been made in the past that IntelliSense errors should be avoided.

Thank you for your review.

This is a Visual Studio bug with their IntelliSense implementation. http://eel.is/c++draft/cpp.cond#5 says the pp-tokens are to be interpreted as an attribute-token, which includes attribute-scoped-tokens.

Thank you for pointing this out and providing citations. I understand that Windows is a supported platform of LLVM. As a result, I suppose it doesn't matter whose fault this is.

Sort of. We should make sure the issue gets reported to Microsoft, and if it causes us tangible pain, we could work around it locally.

IntelliSense squiggly lines often do not match the compiler behavior (IntelliSense uses a different frontend than cl, from what I understand); why do we need to work around it here? I guess I don't understand what problem this is solving given that the compilation succeeds.

If there isn't already a policy/consensus on whether IntelliSense errors should be avoided (especially in header files), it would be a judgement call.

To the best of my knowledge, no one in the project worries about IntelliSense issues. I'm not certain we've had an explicit policy decision on this, but that's unsurprising given that IntelliSense is not required to build the project.

However, I would expect that the choice had been made in the past. If IntelliSense misbehavior are indeed "often" (as you said), and given that there aren't other IntelliSense complaints of header files in the code base (as far as I can tell), it is likely that a choice had been made in the past that IntelliSense errors should be avoided.

I think there aren't complaints about it because it doesn't have any impact other than putting up red squiggles where it shouldn't (or not having red squiggles where it should) in a text editor. I use the Visual Studio editor all day every day and do not find the IntelliSense issues to be anything more than a very minor distraction.

MSVC *does* support attribute namespaces in their implementation of __has_cpp_attribute (the compiler will parse and appropriately handle it); this is purely an IntelliSense thing, which is a cosmetic editor issue. The proposed changes disallow the macro from gracefully upgrading should Microsoft choose to implement any of the vendor attributes we use in some future version of MSVC. While I don't think that's a likely scenario for the attributes we currently use, I also don't think working around IntelliSense bugs is worth the effort unless there is some appreciable impact from the bug fix.

haozhun abandoned this revision.Jan 28 2019, 2:27 PM

Thank you for the explanation. I'm closing this off.

Thank you for the explanation. I'm closing this off.

Thank you for looking into it! I'll file a report with Microsoft about the IntelliSense issue if you've not already done so.