Skip to content

Commit 7ec1d36

Browse files
committed
Parser: Reject @c attributes using the string format
Reject `@c` attributes in the format of `@c("customName")` to accept only `@c(customName)` and of course the bare `@c`.
1 parent 659692e commit 7ec1d36

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3027,14 +3027,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
30273027
}
30283028

30293029
case DeclAttrKind::CDecl: {
3030-
if (!AttrName.starts_with("_") &&
3031-
3032-
// Backwards support for @c("stringId"). Remove before enabling in
3033-
// production so we accept only the identifier format.
3034-
lookahead(1, [&](CancellableBacktrackingScope &) {
3035-
return Tok.isNot(tok::string_literal);
3036-
})) {
3037-
3030+
if (AttrName == "c") {
30383031
std::optional<StringRef> CName;
30393032
if (consumeIfAttributeLParen()) {
30403033
// Custom C name.

test/attr/attr_cdecl_official.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
// expected-error @-1 {{expected ')' in 'c' attribute}}
1313
// expected-error @-2 {{expected declaration}}
1414

15+
@c("old string syntax") func stringSyntax() {}
16+
// expected-error @-1 {{expected C identifier in 'c' attribute}}
17+
// expected-error @-2 {{expected declaration}}
18+
1519
@c() func emptyParen() {}
1620
// expected-error @-1 {{expected C identifier in 'c' attribute}}
1721
// expected-error @-2 {{expected declaration}}

0 commit comments

Comments
 (0)