@@ -2503,7 +2503,7 @@ static std::optional<Identifier> parseSingleAttrOptionImpl(
25032503 };
25042504 bool isDeclModifier = DeclAttribute::isDeclModifier (DK);
25052505
2506- if (!P.Tok .is (tok::l_paren )) {
2506+ if (!P.Tok .isFollowingLParen ( )) {
25072507 if (allowOmitted)
25082508 return Identifier ();
25092509
@@ -2883,7 +2883,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
28832883 .Case (" public" , AccessLevel::Public)
28842884 .Case (" open" , AccessLevel::Open);
28852885
2886- if (!Tok.is (tok::l_paren )) {
2886+ if (!Tok.isFollowingLParen ( )) {
28872887 // Normal access control attribute.
28882888 AttrRange = Loc;
28892889
@@ -3458,7 +3458,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
34583458 }
34593459 case DeclAttrKind::PrivateImport: {
34603460 // Parse the leading '('.
3461- if (Tok.isNot (tok::l_paren )) {
3461+ if (! Tok.isFollowingLParen ( )) {
34623462 diagnose (Loc, diag::attr_expected_lparen, AttrName,
34633463 DeclAttribute::isDeclModifier (DK));
34643464 return makeParserSuccess ();
@@ -3507,7 +3507,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
35073507 }
35083508 case DeclAttrKind::ObjC: {
35093509 // Unnamed @objc attribute.
3510- if (Tok.isNot (tok::l_paren )) {
3510+ if (! Tok.isFollowingLParen ( )) {
35113511 auto attr = ObjCAttr::createUnnamed (Context, AtLoc, Loc);
35123512 Attributes.add (attr);
35133513 break ;
@@ -3575,7 +3575,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
35753575
35763576 case DeclAttrKind::DynamicReplacement: {
35773577 // Parse the leading '('.
3578- if (Tok.isNot (tok::l_paren )) {
3578+ if (! Tok.isFollowingLParen ( )) {
35793579 diagnose (Loc, diag::attr_expected_lparen, AttrName,
35803580 DeclAttribute::isDeclModifier (DK));
35813581 return makeParserSuccess ();
@@ -3626,7 +3626,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
36263626
36273627 case DeclAttrKind::TypeEraser: {
36283628 // Parse leading '('
3629- if (Tok.isNot (tok::l_paren )) {
3629+ if (! Tok.isFollowingLParen ( )) {
36303630 diagnose (Loc, diag::attr_expected_lparen, AttrName,
36313631 DeclAttribute::isDeclModifier (DK));
36323632 return makeParserSuccess ();
@@ -3656,7 +3656,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
36563656
36573657 case DeclAttrKind::Specialize:
36583658 case DeclAttrKind::Specialized: {
3659- if (Tok.isNot (tok::l_paren )) {
3659+ if (! Tok.isFollowingLParen ( )) {
36603660 diagnose (Loc, diag::attr_expected_lparen, AttrName,
36613661 DeclAttribute::isDeclModifier (DK));
36623662 return makeParserSuccess ();
@@ -3885,7 +3885,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
38853885 break ;
38863886 }
38873887 case DeclAttrKind::RawLayout: {
3888- if (Tok.isNot (tok::l_paren )) {
3888+ if (! Tok.isFollowingLParen ( )) {
38893889 diagnose (Loc, diag::attr_expected_lparen, AttrName,
38903890 DeclAttribute::isDeclModifier (DK));
38913891 return makeParserSuccess ();
@@ -4187,7 +4187,7 @@ ParserResult<CustomAttr> Parser::parseCustomAttribute(SourceLoc atLoc) {
41874187 // Parse a custom attribute.
41884188 auto type = parseType (diag::expected_type, ParseTypeReason::CustomAttribute);
41894189 if (type.hasCodeCompletion () || type.isNull ()) {
4190- if (Tok.is (tok::l_paren ) && isCustomAttributeArgument ())
4190+ if (Tok.isFollowingLParen ( ) && isCustomAttributeArgument ())
41914191 skipSingle ();
41924192
41934193 return ParserResult<CustomAttr>(ParserStatus (type));
@@ -4369,7 +4369,7 @@ ParserStatus Parser::parseDeclAttribute(DeclAttributes &Attributes,
43694369 SourceLoc attrLoc = consumeToken ();
43704370
43714371 // @warn_unused_result with no arguments.
4372- if (Tok.isNot (tok::l_paren )) {
4372+ if (! Tok.isFollowingLParen ( )) {
43734373 diagnose (AtLoc, diag::attr_warn_unused_result_removed)
43744374 .fixItRemove (SourceRange (AtLoc, attrLoc));
43754375
@@ -4453,7 +4453,7 @@ ParserStatus Parser::parseDeclAttribute(DeclAttributes &Attributes,
44534453
44544454 // Recover by eating @foo(...) when foo is not known.
44554455 consumeToken ();
4456- if (Tok.is (tok::l_paren ))
4456+ if (Tok.isFollowingLParen ( ))
44574457 skipSingle ();
44584458
44594459 return makeParserError ();
@@ -5925,7 +5925,7 @@ bool Parser::isStartOfSwiftDecl(bool allowPoundIfAttributes,
59255925 // If it might be, we do some more digging.
59265926
59275927 // If this is 'unowned', check to see if it is valid.
5928- if (Tok.getText () == " unowned" && Tok2.is (tok::l_paren )) {
5928+ if (Tok.getText () == " unowned" && Tok2.isFollowingLParen ( )) {
59295929 Parser::BacktrackingScope Backtrack (*this );
59305930 if (consumeIfParenthesizedUnowned (*this )) {
59315931 return isStartOfSwiftDecl (/* allowPoundIfAttributes=*/ false ,
@@ -5934,7 +5934,7 @@ bool Parser::isStartOfSwiftDecl(bool allowPoundIfAttributes,
59345934 }
59355935
59365936 // If this is 'nonisolated', check to see if it is valid.
5937- if (Tok.isContextualKeyword (" nonisolated" ) && Tok2.is (tok::l_paren )) {
5937+ if (Tok.isContextualKeyword (" nonisolated" ) && Tok2.isFollowingLParen ( )) {
59385938 BacktrackingScope backtrack (*this );
59395939 if (consumeIfParenthesizedNonisolated (*this )) {
59405940 return isStartOfSwiftDecl (/* allowPoundIfAttributes=*/ false ,
@@ -7277,6 +7277,12 @@ ParserStatus Parser::parseDeclPoundDiagnostic() {
72777277 bool isError = Tok.is (tok::pound_error);
72787278 consumeToken (isError ? tok::pound_error : tok::pound_warning);
72797279
7280+ if (Tok.isAtStartOfLine ()) {
7281+ diagnose (Tok, diag::pound_diagnostic_expected_parens, isError)
7282+ .fixItInsertAfter (PreviousLoc, " (\" <#message#>\" )" );
7283+ return makeParserSuccess ();
7284+ }
7285+
72807286 SourceLoc lParenLoc = Tok.getLoc ();
72817287 bool hadLParen = consumeIf (tok::l_paren);
72827288
@@ -7373,7 +7379,7 @@ ParserStatus Parser::parseLineDirective(bool isLine) {
73737379
73747380 unsigned StartLine = 0 ;
73757381 std::optional<StringRef> Filename;
7376- if (!isLine) {
7382+ if (!isLine && !Tok. isAtStartOfLine () ) {
73777383 // #sourceLocation()
73787384 // #sourceLocation(file: "foo", line: 42)
73797385 if (parseToken (tok::l_paren, diag::sourceLocation_expected, " (" ))
0 commit comments