Skip to content

Commit db63a94

Browse files
committed
[Macros] Emit deprecation warnings for uses of freestanding macros.
Fixes rdar://113138432. (cherry picked from commit 0a1fbe7)
1 parent 2211b2c commit db63a94

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3252,6 +3252,11 @@ class ExprAvailabilityWalker : public ASTWalker {
32523252
}
32533253
}
32543254

3255+
if (auto ME = dyn_cast<MacroExpansionExpr>(E)) {
3256+
diagnoseDeclRefAvailability(
3257+
ME->getMacroRef(), ME->getMacroNameLoc().getSourceRange());
3258+
}
3259+
32553260
return Action::Continue(E);
32563261
}
32573262

test/Macros/macro_expand.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,3 +546,23 @@ func testExpressionAsDeclarationMacro() {
546546
// expected-error@-1{{macro implementation type 'StringifyMacro' doesn't conform to required protocol 'DeclarationMacro' (from macro 'stringifyAsDeclMacro')}}
547547
#endif
548548
}
549+
550+
// Deprecated macro
551+
@available(*, deprecated, message: "This macro is deprecated.")
552+
@freestanding(expression) macro deprecatedStringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "MacroDefinition", type: "StringifyMacro")
553+
554+
@available(*, deprecated, message: "This macro is deprecated.")
555+
@freestanding(declaration) macro deprecatedStringifyAsDeclMacro<T>(_ value: T) = #externalMacro(module: "MacroDefinition", type: "StringifyMacro")
556+
557+
func testDeprecated() {
558+
// expected-warning@+1{{'deprecatedStringify' is deprecated: This macro is deprecated.}}
559+
_ = #deprecatedStringify(1 + 1)
560+
}
561+
562+
#if TEST_DIAGNOSTICS
563+
struct DeprecatedStructWrapper {
564+
// expected-error@+2{{macro implementation type 'StringifyMacro' doesn't conform to required protocol 'DeclarationMacro' (from macro 'deprecatedStringifyAsDeclMacro')}}
565+
// expected-warning@+1{{'deprecatedStringifyAsDeclMacro' is deprecated: This macro is deprecated.}}
566+
#deprecatedStringifyAsDeclMacro(1 + 1)
567+
}
568+
#endif

0 commit comments

Comments
 (0)