Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lex arguments for __has_cpp_attribute and friends as expanded tokens
The C and C++ standards require the argument to __has_cpp_attribute and __has_c_attribute to be expanded ([cpp.cond]p5). It would make little sense to expand the argument to those operators but not expand the argument to __has_attribute and __has_declspec, so those were both also changed in this patch. Note that it might make sense for the other builtins to also expand their argument, but it wasn't as clear to me whether the behavior would be correct there, and so they were left for a future revision.
- Loading branch information
1 parent
2e0fb00
commit 2edb89c
Showing
6 changed files
with
152 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// RUN: %clang_cc1 -triple i386-unknown-unknown -Eonly -verify %s | ||
|
||
// We warn users if they write an attribute like | ||
// [[__clang__::fallthrough]] because __clang__ is a macro that expands to 1. | ||
// Instead, we suggest users use [[_Clang::fallthrough]] in this situation. | ||
// However, because __has_cpp_attribute (and __has_c_attribute) require | ||
// expanding their argument tokens, __clang__ expands to 1 in the feature test | ||
// macro as well. We don't currently give users a kind warning in this case, | ||
// but we previously did not expand macros and so this would return 0. Now that | ||
// we properly expand macros, users will now get an error about using incorrect | ||
// syntax. | ||
|
||
__has_cpp_attribute(__clang__::fallthrough) // expected-error {{missing ')' after <numeric_constant>}} \ | ||
// expected-note {{to match this '('}} \ | ||
// expected-error {{builtin feature check macro requires a parenthesized identifier}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters